src/EventListener/MaintenanceListener.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\HttpFoundation\Response;
  6. class MaintenanceListener
  7. {
  8.     private $container;
  9.     public function __construct(ContainerInterface $container){
  10.         $this->container $container;
  11.     }
  12.     
  13.     public function onKernelRequest(GetResponseEvent $event){
  14.         $maintenance $this->container->hasParameter('maintenance') ? $this->container->getParameter('maintenance') : false;
  15.         if($maintenance){
  16.             $engine $this->container->get('templating');
  17.             $template $engine->render('maintenance.html.twig');
  18.             $event->setResponse(new Response($template,503));
  19.             $event->stopPropagation();
  20.         }
  21.     }
  22. }