vendor/liip/functional-test-bundle/src/Validator/DataCollectingValidator.php line 43

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the Liip/FunctionalTestBundle
  5.  *
  6.  * (c) Lukas Kahwe Smith <smith@pooteeweet.org>
  7.  *
  8.  * This source file is subject to the MIT license that is bundled
  9.  * with this source code in the file LICENSE.
  10.  */
  11. namespace Liip\FunctionalTestBundle\Validator;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. use Symfony\Component\Validator\ConstraintViolationList;
  15. use Symfony\Component\Validator\ConstraintViolationListInterface;
  16. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  17. use Symfony\Component\Validator\Mapping\MetadataInterface;
  18. use Symfony\Component\Validator\Validator\ContextualValidatorInterface;
  19. use Symfony\Component\Validator\Validator\ValidatorInterface;
  20. class DataCollectingValidator implements ValidatorInterfaceEventSubscriberInterface
  21. {
  22.     /**
  23.      * @var ValidatorInterface
  24.      */
  25.     protected $wrappedValidator;
  26.     /**
  27.      * @var ConstraintViolationListInterface
  28.      */
  29.     protected $lastErrors;
  30.     public function __construct(ValidatorInterface $wrappedValidator)
  31.     {
  32.         $this->wrappedValidator $wrappedValidator;
  33.         $this->clearLastErrors();
  34.     }
  35.     public function clearLastErrors(): void
  36.     {
  37.         $this->lastErrors = new ConstraintViolationList();
  38.     }
  39.     public function getLastErrors(): ConstraintViolationListInterface
  40.     {
  41.         return $this->lastErrors;
  42.     }
  43.     public function getMetadataFor($value): MetadataInterface
  44.     {
  45.         return $this->wrappedValidator->getMetadataFor($value);
  46.     }
  47.     public function hasMetadataFor($value): bool
  48.     {
  49.         return $this->wrappedValidator->hasMetadataFor($value);
  50.     }
  51.     public function validate($value$constraints null$groups null): ConstraintViolationListInterface
  52.     {
  53.         return $this->lastErrors $this->wrappedValidator->validate($value$constraints$groups);
  54.     }
  55.     public function validateProperty($object$propertyName$groups null): ConstraintViolationListInterface
  56.     {
  57.         return $this->wrappedValidator->validateProperty($object$propertyName$groups);
  58.     }
  59.     public function validatePropertyValue($objectOrClass$propertyName$value$groups null): ConstraintViolationListInterface
  60.     {
  61.         return $this->wrappedValidator->validatePropertyValue($objectOrClass$propertyName$value$groups);
  62.     }
  63.     public function startContext(): ContextualValidatorInterface
  64.     {
  65.         return $this->wrappedValidator->startContext();
  66.     }
  67.     public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface
  68.     {
  69.         return $this->wrappedValidator->inContext($context);
  70.     }
  71.     public static function getSubscribedEvents(): array
  72.     {
  73.         return [
  74.             KernelEvents::REQUEST => ['clearLastErrors'99999],
  75.         ];
  76.     }
  77. }