1 | <?php |
||
26 | class DataCollectingValidator implements ValidatorInterface, EventSubscriberInterface |
||
27 | { |
||
28 | /** |
||
29 | * @var ValidatorInterface |
||
30 | */ |
||
31 | protected $wrappedValidator; |
||
32 | |||
33 | /** |
||
34 | * @var ConstraintViolationListInterface |
||
35 | */ |
||
36 | protected $lastErrors; |
||
37 | |||
38 | 19 | public function __construct(ValidatorInterface $wrappedValidator) |
|
39 | { |
||
40 | 19 | $this->wrappedValidator = $wrappedValidator; |
|
41 | 19 | $this->clearLastErrors(); |
|
42 | 19 | } |
|
43 | |||
44 | 19 | public function clearLastErrors(): void |
|
45 | { |
||
46 | 19 | $this->lastErrors = new ConstraintViolationList(); |
|
47 | 19 | } |
|
48 | |||
49 | 5 | public function getLastErrors(): ConstraintViolationListInterface |
|
50 | { |
||
51 | 5 | return $this->lastErrors; |
|
52 | } |
||
53 | |||
54 | public function getMetadataFor($value): MetadataInterface |
||
55 | { |
||
56 | return $this->wrappedValidator->getMetadataFor($value); |
||
57 | } |
||
58 | |||
59 | public function hasMetadataFor($value): bool |
||
60 | { |
||
61 | return $this->wrappedValidator->hasMetadataFor($value); |
||
62 | } |
||
63 | |||
64 | 4 | public function validate($value, $constraints = null, $groups = null): ConstraintViolationListInterface |
|
65 | { |
||
66 | 4 | return $this->lastErrors = $this->wrappedValidator->validate($value, $constraints, $groups); |
|
67 | } |
||
68 | |||
69 | public function validateProperty($object, $propertyName, $groups = null): ConstraintViolationListInterface |
||
70 | { |
||
71 | return $this->wrappedValidator->validateProperty($object, $propertyName, $groups); |
||
72 | } |
||
73 | |||
74 | public function validatePropertyValue($objectOrClass, $propertyName, $value, $groups = null): ConstraintViolationListInterface |
||
75 | { |
||
76 | return $this->wrappedValidator->validatePropertyValue($objectOrClass, $propertyName, $value, $groups); |
||
77 | } |
||
78 | |||
79 | public function startContext(): ContextualValidatorInterface |
||
80 | { |
||
81 | return $this->wrappedValidator->startContext(); |
||
82 | } |
||
83 | |||
84 | public function inContext(ExecutionContextInterface $context): ContextualValidatorInterface |
||
85 | { |
||
86 | return $this->wrappedValidator->inContext($context); |
||
87 | } |
||
88 | |||
89 | 19 | public function onKernelRequest(GetResponseEvent $event): void |
|
95 | |||
96 | 3 | public static function getSubscribedEvents(): array |
|
97 | { |
||
98 | return [ |
||
99 | 3 | KernelEvents::REQUEST => ['onKernelRequest', 99999], |
|
100 | ]; |
||
101 | } |
||
102 | } |
||
103 |