Factory
1 year ago
Loader
1 year ago
AutoMappingStrategy.php
4 years ago
CascadingStrategy.php
4 years ago
ClassMetadata.php
1 year ago
ClassMetadataInterface.php
4 years ago
GenericMetadata.php
4 years ago
GetterMetadata.php
1 year ago
MemberMetadata.php
4 years ago
MetadataInterface.php
4 years ago
PropertyMetadata.php
5 months ago
PropertyMetadataInterface.php
4 years ago
TraversalStrategy.php
4 years ago
index.php
3 years ago
GenericMetadata.php
88 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator\Mapping; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Symfony\Component\Validator\Constraint; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Constraints\Cascade; |
| 6 | use MailPoetVendor\Symfony\Component\Validator\Constraints\DisableAutoMapping; |
| 7 | use MailPoetVendor\Symfony\Component\Validator\Constraints\EnableAutoMapping; |
| 8 | use MailPoetVendor\Symfony\Component\Validator\Constraints\Traverse; |
| 9 | use MailPoetVendor\Symfony\Component\Validator\Constraints\Valid; |
| 10 | use MailPoetVendor\Symfony\Component\Validator\Exception\ConstraintDefinitionException; |
| 11 | class GenericMetadata implements MetadataInterface |
| 12 | { |
| 13 | public $constraints = []; |
| 14 | public $constraintsByGroup = []; |
| 15 | public $cascadingStrategy = CascadingStrategy::NONE; |
| 16 | public $traversalStrategy = TraversalStrategy::NONE; |
| 17 | public $autoMappingStrategy = AutoMappingStrategy::NONE; |
| 18 | public function __sleep() |
| 19 | { |
| 20 | return ['constraints', 'constraintsByGroup', 'cascadingStrategy', 'traversalStrategy', 'autoMappingStrategy']; |
| 21 | } |
| 22 | public function __clone() |
| 23 | { |
| 24 | $constraints = $this->constraints; |
| 25 | $this->constraints = []; |
| 26 | $this->constraintsByGroup = []; |
| 27 | foreach ($constraints as $constraint) { |
| 28 | $this->addConstraint(clone $constraint); |
| 29 | } |
| 30 | } |
| 31 | public function addConstraint(Constraint $constraint) |
| 32 | { |
| 33 | if ($constraint instanceof Traverse || $constraint instanceof Cascade) { |
| 34 | throw new ConstraintDefinitionException(\sprintf('The constraint "%s" can only be put on classes. Please use "Symfony\\Component\\Validator\\Constraints\\Valid" instead.', \get_debug_type($constraint))); |
| 35 | } |
| 36 | if ($constraint instanceof Valid && null === $constraint->groups) { |
| 37 | $this->cascadingStrategy = CascadingStrategy::CASCADE; |
| 38 | if ($constraint->traverse) { |
| 39 | $this->traversalStrategy = TraversalStrategy::IMPLICIT; |
| 40 | } else { |
| 41 | $this->traversalStrategy = TraversalStrategy::NONE; |
| 42 | } |
| 43 | return $this; |
| 44 | } |
| 45 | if ($constraint instanceof DisableAutoMapping || $constraint instanceof EnableAutoMapping) { |
| 46 | $this->autoMappingStrategy = $constraint instanceof EnableAutoMapping ? AutoMappingStrategy::ENABLED : AutoMappingStrategy::DISABLED; |
| 47 | // The constraint is not added |
| 48 | return $this; |
| 49 | } |
| 50 | $this->constraints[] = $constraint; |
| 51 | foreach ($constraint->groups as $group) { |
| 52 | $this->constraintsByGroup[$group][] = $constraint; |
| 53 | } |
| 54 | return $this; |
| 55 | } |
| 56 | public function addConstraints(array $constraints) |
| 57 | { |
| 58 | foreach ($constraints as $constraint) { |
| 59 | $this->addConstraint($constraint); |
| 60 | } |
| 61 | return $this; |
| 62 | } |
| 63 | public function getConstraints() |
| 64 | { |
| 65 | return $this->constraints; |
| 66 | } |
| 67 | public function hasConstraints() |
| 68 | { |
| 69 | return \count($this->constraints) > 0; |
| 70 | } |
| 71 | public function findConstraints(string $group) |
| 72 | { |
| 73 | return $this->constraintsByGroup[$group] ?? []; |
| 74 | } |
| 75 | public function getCascadingStrategy() |
| 76 | { |
| 77 | return $this->cascadingStrategy; |
| 78 | } |
| 79 | public function getTraversalStrategy() |
| 80 | { |
| 81 | return $this->traversalStrategy; |
| 82 | } |
| 83 | public function getAutoMappingStrategy() : int |
| 84 | { |
| 85 | return $this->autoMappingStrategy; |
| 86 | } |
| 87 | } |
| 88 |