| Total Complexity | 5 |
| Total Lines | 51 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 12 | class RequestSchemaValidatorListener |
||
| 13 | { |
||
| 14 | use ControllerAnnotationExtractorTrait; |
||
| 15 | |||
| 16 | public const ATTRIBUTE_RESPONSE_SCHEMAS = 'spiechu_symfony_commons.event_listener.response_schemas'; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @var Reader |
||
| 20 | */ |
||
| 21 | protected $annotationReader; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @param Reader $annotationReader |
||
| 25 | */ |
||
| 26 | 22 | public function __construct(Reader $annotationReader) |
|
| 29 | 22 | } |
|
| 30 | |||
| 31 | /** |
||
| 32 | * @param FilterControllerEvent $event |
||
| 33 | */ |
||
| 34 | 22 | public function onKernelController(FilterControllerEvent $event): void |
|
| 35 | { |
||
| 36 | 22 | $responseSchemaValidator = $this->getResponseSchemaValidator($event->getController()); |
|
| 37 | |||
| 38 | 22 | if (!$responseSchemaValidator instanceof ResponseSchemaValidator) { |
|
| 39 | 16 | return; |
|
| 40 | } |
||
| 41 | |||
| 42 | 6 | $event->getRequest()->attributes->set(static::ATTRIBUTE_RESPONSE_SCHEMAS, $responseSchemaValidator->getSchemas()); |
|
| 43 | 6 | } |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @param callable $controller |
||
| 47 | * |
||
| 48 | * @throws \ReflectionException |
||
| 49 | * |
||
| 50 | * @return null|ResponseSchemaValidator |
||
| 51 | */ |
||
| 52 | 22 | protected function getResponseSchemaValidator(callable $controller): ?ResponseSchemaValidator |
|
| 53 | { |
||
| 54 | 22 | return $this->getMethodAnnotationFromController($controller, ResponseSchemaValidator::class); |
|
| 55 | } |
||
| 56 | |||
| 57 | /** |
||
| 58 | * {@inheritdoc} |
||
| 59 | */ |
||
| 60 | 22 | protected function getAnnotationReader(): Reader |
|
| 63 | } |
||
| 64 | } |
||
| 65 |