<?php
namespace App\EventListener;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Response;
class MaintenanceListener
{
private $container;
public function __construct(ContainerInterface $container){
$this->container = $container;
}
public function onKernelRequest(GetResponseEvent $event){
$maintenance = $this->container->hasParameter('maintenance') ? $this->container->getParameter('maintenance') : false;
if($maintenance){
$engine = $this->container->get('templating');
$template = $engine->render('maintenance.html.twig');
$event->setResponse(new Response($template,503));
$event->stopPropagation();
}
}
}