Traverse.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. * @Annotation
  15. *
  16. * @author Bernhard Schussek <bschussek@gmail.com>
  17. */
  18. #[\Attribute(\Attribute::TARGET_CLASS)]
  19. class Traverse extends Constraint
  20. {
  21. public $traverse = true;
  22. /**
  23. * @param bool|array|null $traverse
  24. */
  25. public function __construct($traverse = null)
  26. {
  27. if (\is_array($traverse) && \array_key_exists('groups', $traverse)) {
  28. throw new ConstraintDefinitionException(sprintf('The option "groups" is not supported by the constraint "%s".', __CLASS__));
  29. }
  30. parent::__construct($traverse);
  31. }
  32. /**
  33. * {@inheritdoc}
  34. */
  35. public function getDefaultOption()
  36. {
  37. return 'traverse';
  38. }
  39. /**
  40. * {@inheritdoc}
  41. */
  42. public function getTargets()
  43. {
  44. return self::CLASS_CONSTRAINT;
  45. }
  46. }