src/EventListener/MaintenanceListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. // use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  6. use Symfony\Component\DependencyInjection\ContainerInterface;
  7. class MaintenanceListener
  8. {
  9.     private $container;
  10.     public function __construct(ContainerInterface $container) {
  11.         $this->container $container;
  12.     }
  13.     public function onKernelRequest(RequestEvent $event) {
  14.         // Verifie si un fichier maintenance.lock existe a la racine de l'application
  15.         $maintenance file_exists($this->container->getParameter("kernel.project_dir") . DIRECTORY_SEPARATOR "maintenance.lock");
  16.         // Si l'application est en maintenance, afficher la page de maintenance
  17.         if($maintenance) {
  18.             $template $this->container->get("twig")->render("maintenance.html.twig");
  19.             $event->setResponse(new Response($template302));
  20.             $event->stopPropagation();
  21.         }
  22.     }
  23. }