AbstractComparison.php 1.2 KB

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