vendor/logist/maintenance-bundle/src/LogistMaintenanceBundle/EventListener/MaintenanceListener.php line 32

Open in your IDE?
  1. <?php
  2. namespace LogistMaintenanceBundle\EventListener;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use LogistMaintenanceBundle\Service\LogistMaintenancePlaceholderService;
  5. class MaintenanceListener
  6. {
  7.     const MAINTENANCE_ERROR_CODE 503;
  8.     /**
  9.      * @var boolean
  10.      */
  11.     protected $isTriggered FALSE;
  12.     /**
  13.      * @var LogistMaintenancePlaceholderService
  14.      */
  15.     protected $placeholderService;
  16.     /**
  17.      * @param LogistMaintenancePlaceholderService $placeholderService
  18.      */
  19.     public function __construct(LogistMaintenancePlaceholderService $placeholderService)
  20.     {
  21.         $this->placeholderService $placeholderService;
  22.     }
  23.     public function onKernelRequest($event)
  24.     {
  25.         if(
  26.             ($this->placeholderService->getMode() === LogistMaintenancePlaceholderService::MODE_ENABLED)
  27.             && !$this->isTriggered // to prevent endless loop with render controller in template
  28.         ){
  29.             $this->isTriggered TRUE;
  30.             $body $this->placeholderService->renderPlaceholder();       
  31.             $response = new Response(
  32.                 $body
  33.                 LogistMaintenancePlaceholderService::MAINTENANCE_ERROR_CODE
  34.                 ['Content-Type' => 'text/html']
  35.             );
  36.             $event->setResponse($response);
  37.             $event->stopPropagation();
  38.         }
  39.     }
  40. }