src/EventListener/MaintenanceListener.php line 21

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Boab\CmsBundle\View\ViewManagerInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. class MaintenanceListener
  8. {
  9.     private $viewManager;
  10.     private $configs;
  11.     public function __construct(ViewManagerInterface $viewManager$configs)
  12.     {
  13.         $this->viewManager $viewManager;
  14.         $this->configs $configs;
  15.     }
  16.     public function onKernelRequest(RequestEvent $event)
  17.     {
  18.         if($event->isMainRequest() && file_exists($this->configs['lock_file'])){
  19.             $view $this->viewManager->load($this->configs['template']);
  20.             // We send our response with a 503 response code (service unavailable)
  21.             $event->setResponse(new Response($view->render(), 503));
  22.             //$event->stopPropagation();
  23.             return;
  24.         }
  25.     }
  26. }