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 Twig\Environment;
  6. class MaintenanceListener
  7. {
  8.     private $maintenance;
  9.     private $twig;
  10.     public function __construct($maintenanceEnvironment $twig)
  11.     {
  12.         $this->maintenance $maintenance;
  13.         $this->twig $twig;
  14.     }
  15.     public function onKernelRequest(RequestEvent $event)
  16.     {
  17.         //onverifier si le fichier .maintenance n'existe pas
  18.         if (!file_exists($this->maintenance)) {
  19.             return;
  20.         }
  21.         $event->setResponse(
  22.             new Response(
  23.                 $this->twig->render('/maintenance/maintenance.html.twig'),
  24.                 Response::HTTP_SERVICE_UNAVAILABLE
  25.             )
  26.         );
  27.         $event->stopPropagation();
  28.     }
  29. }