| Total Complexity | 5 |
| Total Lines | 29 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 15 | abstract class AbstractLazyResponseHandler implements EventSubscriberInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @return string[][] |
||
| 19 | * |
||
| 20 | * @psalm-return array{'kernel.view': array{0: string}} |
||
| 21 | */ |
||
| 22 | 3 | public static function getSubscribedEvents(): array |
|
| 23 | { |
||
| 24 | return [ |
||
| 25 | 3 | KernelEvents::VIEW => ['handleLazyResponse'], |
|
| 26 | ]; |
||
| 27 | } |
||
| 28 | |||
| 29 | 10 | public function handleLazyResponse(ViewEvent $event): void |
|
| 30 | { |
||
| 31 | 10 | $controllerResult = $event->getControllerResult(); |
|
| 32 | 10 | if ($this->isSupportedLazyResponse($controllerResult)) { |
|
| 33 | 10 | $event->setResponse($this->generateResponse($controllerResult)); |
|
| 34 | } |
||
| 35 | 10 | } |
|
| 36 | |||
| 37 | abstract protected function isSupported(LazyResponseInterface $controllerResult): bool; |
||
| 38 | |||
| 39 | abstract protected function generateResponse(LazyResponseInterface $controllerResult): Response; |
||
| 40 | |||
| 41 | 10 | private function isSupportedLazyResponse(mixed $controllerResult): bool |
|
| 44 | } |
||
| 45 | } |
||
| 46 |