123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- <?php
- namespace Symfony\Component\Validator\Mapping;
- use Symfony\Component\Validator\Constraint;
- use Symfony\Component\Validator\Constraints\Traverse;
- use Symfony\Component\Validator\Constraints\Valid;
- use Symfony\Component\Validator\Exception\BadMethodCallException;
- use Symfony\Component\Validator\Exception\ConstraintDefinitionException;
- use Symfony\Component\Validator\ValidationVisitorInterface;
- class GenericMetadata implements MetadataInterface
- {
-
- public $constraints = array();
-
- public $constraintsByGroup = array();
-
- public $cascadingStrategy = CascadingStrategy::NONE;
-
- public $traversalStrategy = TraversalStrategy::NONE;
-
- public function __sleep()
- {
- return array(
- 'constraints',
- 'constraintsByGroup',
- 'cascadingStrategy',
- 'traversalStrategy',
- );
- }
-
- public function __clone()
- {
- $constraints = $this->constraints;
- $this->constraints = array();
- $this->constraintsByGroup = array();
- foreach ($constraints as $constraint) {
- $this->addConstraint(clone $constraint);
- }
- }
-
- public function addConstraint(Constraint $constraint)
- {
- if ($constraint instanceof Traverse) {
- throw new ConstraintDefinitionException(sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\Component\Validator\Constraints\Valid" instead.', \get_class($constraint)));
- }
- if ($constraint instanceof Valid) {
- $this->cascadingStrategy = CascadingStrategy::CASCADE;
- if ($constraint->traverse) {
-
- $this->traversalStrategy = TraversalStrategy::IMPLICIT;
- if (!$constraint->deep) {
- $this->traversalStrategy |= TraversalStrategy::STOP_RECURSION;
- }
- } else {
- $this->traversalStrategy = TraversalStrategy::NONE;
- }
- return $this;
- }
- $this->constraints[] = $constraint;
- foreach ($constraint->groups as $group) {
- $this->constraintsByGroup[$group][] = $constraint;
- }
- return $this;
- }
-
- public function addConstraints(array $constraints)
- {
- foreach ($constraints as $constraint) {
- $this->addConstraint($constraint);
- }
- return $this;
- }
-
- public function getConstraints()
- {
- return $this->constraints;
- }
-
- public function hasConstraints()
- {
- return \count($this->constraints) > 0;
- }
-
- public function findConstraints($group)
- {
- return isset($this->constraintsByGroup[$group])
- ? $this->constraintsByGroup[$group]
- : array();
- }
-
- public function getCascadingStrategy()
- {
- return $this->cascadingStrategy;
- }
-
- public function getTraversalStrategy()
- {
- return $this->traversalStrategy;
- }
-
- public function accept(ValidationVisitorInterface $visitor, $value, $group, $propertyPath)
- {
- throw new BadMethodCallException('Not supported.');
- }
- }
|