src/EventListener/MaintenanceListener.php line 17

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.     {
  11.         $this->maintenance $maintenance;
  12.         $this->twig $twig;
  13.     }
  14.     public function onKernelRequest(RequestEvent $event){
  15.         if(!file_exists($this->maintenance)){
  16.             return;
  17.         }
  18.         $event->setResponse(
  19.           new Response(
  20.               $this->twig->render('maintenance/maintenance.html.twig'),
  21.             //   Response::HTTP_SERVICE_UNAVAILABLE
  22.           )  
  23.         );
  24.         $event->stopPropagation();
  25.     }
  26. }