comparison vendor/symfony/validator/Constraints/AbstractComparison.php @ 14:1fec387a4317

Update Drupal core to 8.5.2 via Composer
author Chris Cannam
date Mon, 23 Apr 2018 09:46:53 +0100
parents 7a779792577d
children 129ea1e6d783
comparison
equal deleted inserted replaced
13:5fb285c0d0e3 14:1fec387a4317
9 * file that was distributed with this source code. 9 * file that was distributed with this source code.
10 */ 10 */
11 11
12 namespace Symfony\Component\Validator\Constraints; 12 namespace Symfony\Component\Validator\Constraints;
13 13
14 use Symfony\Component\PropertyAccess\PropertyAccess;
14 use Symfony\Component\Validator\Constraint; 15 use Symfony\Component\Validator\Constraint;
15 use Symfony\Component\Validator\Exception\ConstraintDefinitionException; 16 use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
16 17
17 /** 18 /**
18 * Used for the comparison of values. 19 * Used for the comparison of values.
22 */ 23 */
23 abstract class AbstractComparison extends Constraint 24 abstract class AbstractComparison extends Constraint
24 { 25 {
25 public $message; 26 public $message;
26 public $value; 27 public $value;
28 public $propertyPath;
27 29
28 /** 30 /**
29 * {@inheritdoc} 31 * {@inheritdoc}
30 */ 32 */
31 public function __construct($options = null) 33 public function __construct($options = null)
32 { 34 {
33 if (null === $options) { 35 if (null === $options) {
34 $options = array(); 36 $options = array();
35 } 37 }
36 38
37 if (is_array($options) && !isset($options['value'])) { 39 if (is_array($options)) {
38 throw new ConstraintDefinitionException(sprintf( 40 if (!isset($options['value']) && !isset($options['propertyPath'])) {
39 'The %s constraint requires the "value" option to be set.', 41 throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', get_class($this)));
40 get_class($this) 42 }
41 )); 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.', get_class($this)));
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.', get_class($this)));
50 }
42 } 51 }
43 52
44 parent::__construct($options); 53 parent::__construct($options);
45 } 54 }
46 55