Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. AbstractComparison.php

function AbstractComparison::__construct

Overrides Constraint::__construct

File

vendor/symfony/validator/Constraints/AbstractComparison.php, line 31

Class

AbstractComparison
Used for the comparison of values.

Namespace

Symfony\Component\Validator\Constraints

Code

public function __construct(mixed $value = null, ?string $propertyPath = null, ?string $message = null, ?array $groups = null, mixed $payload = null, array $options = []) {
    if (\is_array($value)) {
        $options = array_merge($value, $options);
    }
    elseif (null !== $value) {
        $options['value'] = $value;
    }
    parent::__construct($options, $groups, $payload);
    $this->message = $message ?? $this->message;
    $this->propertyPath = $propertyPath ?? $this->propertyPath;
    if (null === $this->value && null === $this->propertyPath) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', static::class));
    }
    if (null !== $this->value && null !== $this->propertyPath) {
        throw new ConstraintDefinitionException(\sprintf('The "%s" constraint requires only one of the "value" or "propertyPath" options to be set, not both.', static::class));
    }
    if (null !== $this->propertyPath && !class_exists(PropertyAccess::class)) {
        throw new LogicException(\sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "propertyPath" option. Try running "composer require symfony/property-access".', static::class));
    }
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal