<?php
namespace Boab\CmsBundle\View\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\ViewEvent;
use Boab\CmsBundle\View\ViewManagerInterface;
use Boab\CmsBundle\View\ViewInterface;
class ResponseListener
{
private $viewManager;
public function __construct(ViewManagerInterface $viewManager)
{
$this->viewManager = $viewManager;
}
public function onKernelView(ViewEvent $event)
{
$request = $event->getRequest();
$view = $event->getControllerResult();
if (!$view instanceof ViewInterface) {
return;
}
$html = $view->render($this->viewManager->getData());
$response = new Response($html);
$response->setStatusCode(200);
$event->setResponse($response);
}
}