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

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