lib/boab/cms-bundle/src/View/EventListener/ResponseListener.php line 28

Open in your IDE?
  1. <?php
  2. namespace Boab\CmsBundle\View\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Event\ViewEvent;
  5. use Boab\CmsBundle\View\ViewManagerInterface;
  6. use Boab\CmsBundle\View\ViewInterface;
  7. class ResponseListener
  8. {
  9.     private $viewManager;
  10.     public function __construct(ViewManagerInterface $viewManager)
  11.     {
  12.         $this->viewManager $viewManager;
  13.     }
  14.     
  15.     public function onKernelView(ViewEvent $event)
  16.     {
  17.         $request $event->getRequest();
  18.         $view $event->getControllerResult();
  19.         if (!$view instanceof ViewInterface) {
  20.             return;
  21.         }
  22.         $html $view->render($this->viewManager->getData());
  23.         $response = new Response($html);
  24.         $response->setStatusCode(200);            
  25.         $event->setResponse($response);
  26.     }