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