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.     private $maintenance;
  8.     private $twig;
  9.     public function __construct($maintenanceEnvironment $twig) {
  10.         $this->maintenance $maintenance;
  11.         $this->twig $twig;
  12.     }
  13.     public function onKernelRequest(RequestEvent $event) {
  14.         // VĂ©rifie si le fichier de maintenance existe
  15.         if(!file_exists($this->maintenance)) {
  16.             return;
  17.         }
  18.         $event->setResponse(
  19.           new Response(
  20.               $this->twig->render('page/maintenance.html.twig'),
  21.               Response::HTTP_SERVICE_UNAVAILABLE
  22.           )
  23.         );
  24.         $event->stopPropagation();
  25.     }
  26. }