src/Event/MaintenanceListener.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Event;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Contracts\EventDispatcher\Event;
  6. use Twig\Environment;
  7. class MaintenanceListener implements EventSubscriberInterface
  8. {
  9.     private $twig;
  10.     public function __construct(Environment $twig){
  11.         $this->twig $twig;
  12.     }
  13.     public static function getSubscribedEvents()
  14.     {
  15.         return [
  16.             'kernel.request' => 'onKernelRequest',
  17.         ];
  18.     }
  19.     public function onKernelRequest(Event $event)
  20.     {
  21.         $isLocked false;
  22.         if ($isLocked === true && $_SERVER['REMOTE_ADDR'] !== '::1') {
  23. //            if ($isLocked === true) {
  24.             $event->setResponse(
  25.                 new Response(
  26.                     $this->twig->render('bundles/TwigBundle/Exception/maintenance.html.twig'),
  27.                     Response::HTTP_SERVICE_UNAVAILABLE
  28.                 )
  29.             );
  30.             $event->stopPropagation();
  31.         }
  32.     }
  33. }