<?php
namespace App\EventListener;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Event\RequestEvent;
// use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\DependencyInjection\ContainerInterface;
class MaintenanceListener
{
private $container;
public function __construct(ContainerInterface $container) {
$this->container = $container;
}
public function onKernelRequest(RequestEvent $event) {
// Verifie si un fichier maintenance.lock existe a la racine de l'application
$maintenance = file_exists($this->container->getParameter("kernel.project_dir") . DIRECTORY_SEPARATOR . "maintenance.lock");
// Si l'application est en maintenance, afficher la page de maintenance
if($maintenance) {
$template = $this->container->get("twig")->render("maintenance.html.twig");
$event->setResponse(new Response($template, 302));
$event->stopPropagation();
}
}
}