src/JsResponse/CustomJsResponseViewListener.php line 11

Open in your IDE?
  1. <?php
  2. namespace App\JsResponse;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\ViewEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. class CustomJsResponseViewListener implements EventSubscriberInterface
  7. {
  8.     public function onKernelView(ViewEvent $event): void
  9.     {
  10.         $result $event->getControllerResult();
  11.         if ($result instanceof CustomJsResponseBuilder) {
  12.             $event->setResponse($result->getResponse());
  13.         }
  14.     }
  15.     /**
  16.      * {@inheritdoc}
  17.      */
  18.     public static function getSubscribedEvents(): array
  19.     {
  20.         return [
  21.             KernelEvents::VIEW => ['onKernelView'40],
  22.         ];
  23.     }
  24. }