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

  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Component\Validator\Constraints;
  11. use Symfony\Component\PropertyAccess\PropertyAccess;
  12. use Symfony\Component\Validator\Constraint;
  13. use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
  14. use Symfony\Component\Validator\Exception\LogicException;
  15. /**
  16.  * Used for the comparison of values.
  17.  *
  18.  * @author Daniel Holmes <daniel@danielholmes.org>
  19.  * @author Bernhard Schussek <bschussek@gmail.com>
  20.  */
  21. abstract class AbstractComparison extends Constraint
  22. {
  23.     public $message;
  24.     public $value;
  25.     public $propertyPath;
  26.     public function __construct(mixed $value nullstring $propertyPath nullstring $message null, array $groups nullmixed $payload null, array $options = [])
  27.     {
  28.         if (\is_array($value)) {
  29.             $options array_merge($value$options);
  30.         } elseif (null !== $value) {
  31.             $options['value'] = $value;
  32.         }
  33.         parent::__construct($options$groups$payload);
  34.         $this->message $message ?? $this->message;
  35.         $this->propertyPath $propertyPath ?? $this->propertyPath;
  36.         if (null === $this->value && null === $this->propertyPath) {
  37.             throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', static::class));
  38.         }
  39.         if (null !== $this->value && null !== $this->propertyPath) {
  40.             throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires only one of the "value" or "propertyPath" options to be set, not both.', static::class));
  41.         }
  42.         if (null !== $this->propertyPath && !class_exists(PropertyAccess::class)) {
  43.             throw new LogicException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "propertyPath" option.', static::class));
  44.         }
  45.     }
  46.     public function getDefaultOption(): ?string
  47.     {
  48.         return 'value';
  49.     }
  50. }