Command
3 years ago
Constraints
3 years ago
Context
3 years ago
Exception
3 years ago
Mapping
3 years ago
Util
3 years ago
Validator
3 years ago
Violation
3 years ago
Constraint.php
4 years ago
ConstraintValidator.php
4 years ago
ConstraintValidatorFactory.php
4 years ago
ConstraintValidatorFactoryInterface.php
4 years ago
ConstraintValidatorInterface.php
4 years ago
ConstraintViolation.php
4 years ago
ConstraintViolationInterface.php
4 years ago
ConstraintViolationList.php
4 years ago
ConstraintViolationListInterface.php
4 years ago
ContainerConstraintValidatorFactory.php
4 years ago
GroupSequenceProviderInterface.php
4 years ago
ObjectInitializerInterface.php
4 years ago
Validation.php
4 years ago
ValidatorBuilder.php
4 years ago
index.php
3 years ago
ContainerConstraintValidatorFactory.php
35 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Symfony\Component\Validator; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | use MailPoetVendor\Psr\Container\ContainerInterface; |
| 5 | use MailPoetVendor\Symfony\Component\Validator\Exception\UnexpectedTypeException; |
| 6 | use MailPoetVendor\Symfony\Component\Validator\Exception\ValidatorException; |
| 7 | class ContainerConstraintValidatorFactory implements ConstraintValidatorFactoryInterface |
| 8 | { |
| 9 | private $container; |
| 10 | private $validators; |
| 11 | public function __construct(ContainerInterface $container) |
| 12 | { |
| 13 | $this->container = $container; |
| 14 | $this->validators = []; |
| 15 | } |
| 16 | public function getInstance(Constraint $constraint) |
| 17 | { |
| 18 | $name = $constraint->validatedBy(); |
| 19 | if (!isset($this->validators[$name])) { |
| 20 | if ($this->container->has($name)) { |
| 21 | $this->validators[$name] = $this->container->get($name); |
| 22 | } else { |
| 23 | if (!\class_exists($name)) { |
| 24 | throw new ValidatorException(\sprintf('Constraint validator "%s" does not exist or is not enabled. Check the "validatedBy" method in your constraint class "%s".', $name, \get_debug_type($constraint))); |
| 25 | } |
| 26 | $this->validators[$name] = new $name(); |
| 27 | } |
| 28 | } |
| 29 | if (!$this->validators[$name] instanceof ConstraintValidatorInterface) { |
| 30 | throw new UnexpectedTypeException($this->validators[$name], ConstraintValidatorInterface::class); |
| 31 | } |
| 32 | return $this->validators[$name]; |
| 33 | } |
| 34 | } |
| 35 |