"Fossies" - the Fresh Open Source Software Archive

Member "drupal-9.4.5/vendor/symfony/validator/Constraints/AbstractComparison.php" (20 Jul 2022, 1977 Bytes) of package /linux/www/drupal-9.4.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

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