<?php
namespace App\EventListener;
use Boab\CmsBundle\View\ViewManagerInterface;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\Event\RequestEvent;
class MaintenanceListener
{
private $viewManager;
private $configs;
public function __construct(ViewManagerInterface $viewManager, $configs)
{
$this->viewManager = $viewManager;
$this->configs = $configs;
}
public function onKernelRequest(RequestEvent $event)
{
if($event->isMainRequest() && file_exists($this->configs['lock_file'])){
$view = $this->viewManager->load($this->configs['template']);
// We send our response with a 503 response code (service unavailable)
$event->setResponse(new Response($view->render(), 503));
//$event->stopPropagation();
return;
}
}
}