"Fossies" - the Fresh Open Source Software Archive

Member "Symfony/vendor/symfony/symfony/src/Symfony/Component/Validator/Constraints/AbstractComparison.php" (30 Mar 2020, 1934 Bytes) of package /linux/www/Symfony_Standard_Vendors_3.4.39.tgz:


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. For more information about "AbstractComparison.php" see the Fossies "Dox" file reference documentation.

    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 
   18 /**
   19  * Used for the comparison of values.
   20  *
   21  * @author Daniel Holmes <daniel@danielholmes.org>
   22  * @author Bernhard Schussek <bschussek@gmail.com>
   23  */
   24 abstract class AbstractComparison extends Constraint
   25 {
   26     public $message;
   27     public $value;
   28     public $propertyPath;
   29 
   30     /**
   31      * {@inheritdoc}
   32      */
   33     public function __construct($options = null)
   34     {
   35         if (null === $options) {
   36             $options = [];
   37         }
   38 
   39         if (\is_array($options)) {
   40             if (!isset($options['value']) && !isset($options['propertyPath'])) {
   41                 throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', static::class));
   42             }
   43 
   44             if (isset($options['value']) && isset($options['propertyPath'])) {
   45                 throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires only one of the "value" or "propertyPath" options to be set, not both.', static::class));
   46             }
   47 
   48             if (isset($options['propertyPath']) && !class_exists(PropertyAccess::class)) {
   49                 throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "propertyPath" option.', static::class));
   50             }
   51         }
   52 
   53         parent::__construct($options);
   54     }
   55 
   56     /**
   57      * {@inheritdoc}
   58      */
   59     public function getDefaultOption()
   60     {
   61         return 'value';
   62     }
   63 }