src/EventSubscriber/ViewSubscriber.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\Event\ViewEvent;
  6. use Symfony\Component\HttpKernel\KernelEvents;
  7. class ViewSubscriber implements EventSubscriberInterface
  8. {
  9.     public static function getSubscribedEvents()
  10.     {
  11.         // return the subscribed events, their methods and priorities
  12.         return [
  13.             KernelEvents::VIEW => [
  14.                 ['onKernelView'0],
  15.             ],
  16.         ];
  17.     }
  18.     public function onKernelView(ViewEvent $event)
  19.     {
  20.         $response = new Response();
  21.         $response->setContent(bencode(
  22.             $event->getControllerResult()
  23.         ));
  24.         $event->setResponse($response);
  25.     }
  26. }