src/EventListener/MaintenanceListener.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\HttpKernel\Event\RequestEvent;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Twig\Environment;
  6. class MaintenanceListener
  7. {
  8.     private $templating;
  9.     private $maintenance;
  10.     public function __construct(Environment $templating)
  11.     {
  12.         $this->templating $templating;
  13.         $this->maintenance $_ENV['MAINTENANCE'];
  14.     }
  15.     public function onKernelRequest(RequestEvent $event)
  16.     {
  17.         $request $event->getRequest();
  18.         $path preg_match("/(^\/moderate\/|^\/login|^\/2fa)(.*)/i"$event->getRequest()->getrequestUri());
  19.         $navbar preg_match("/(^App\\\\Controller\\\\NavigationController::navigation)/i"$event->getRequest()->attributes->get('_controller') );
  20.         $sidebar preg_match("/(^App\\\\Controller\\\\DonationsController::sidebar)/i"$event->getRequest()->attributes->get('_controller') );
  21.         if ($this->maintenance == "true" && $path == false && $navbar == false && $sidebar == false) {
  22.             $event->setResponse(
  23.                 new Response(
  24.                     $this->templating->render('maintenance.html.twig'),
  25.                     Response::HTTP_SERVICE_UNAVAILABLE
  26.                 )
  27.              );
  28.             $event->stopPropagation();
  29.         } else {
  30.             
  31.         }
  32.     }
  33. }