Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Validator\Constraints; Chris@0: Chris@14: use Symfony\Component\PropertyAccess\PropertyAccess; Chris@0: use Symfony\Component\Validator\Constraint; Chris@0: use Symfony\Component\Validator\Exception\ConstraintDefinitionException; Chris@0: Chris@0: /** Chris@0: * Used for the comparison of values. Chris@0: * Chris@0: * @author Daniel Holmes Chris@0: * @author Bernhard Schussek Chris@0: */ Chris@0: abstract class AbstractComparison extends Constraint Chris@0: { Chris@0: public $message; Chris@0: public $value; Chris@14: public $propertyPath; Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function __construct($options = null) Chris@0: { Chris@12: if (null === $options) { Chris@17: $options = []; Chris@12: } Chris@12: Chris@17: if (\is_array($options)) { Chris@14: if (!isset($options['value']) && !isset($options['propertyPath'])) { Chris@17: throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires either the "value" or "propertyPath" option to be set.', \get_class($this))); Chris@14: } Chris@14: Chris@14: if (isset($options['value']) && isset($options['propertyPath'])) { Chris@17: 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@14: } Chris@14: Chris@14: if (isset($options['propertyPath']) && !class_exists(PropertyAccess::class)) { Chris@17: throw new ConstraintDefinitionException(sprintf('The "%s" constraint requires the Symfony PropertyAccess component to use the "propertyPath" option.', \get_class($this))); Chris@14: } Chris@0: } Chris@0: Chris@0: parent::__construct($options); Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function getDefaultOption() Chris@0: { Chris@0: return 'value'; Chris@0: } Chris@0: }