- <?php 
- 
- namespace App\EventListener;
- 
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpKernel\Event\RequestEvent;
- use Twig\Environment;
- 
- class MaintenanceListener{
- 
-     //private const AUTHORIZED_IP = '82.65.24.15';
-     private $authorizedIp;
-     private $maintenance;
-     private $twig;
-     
-     public function __construct($maintenance, Environment $twig, $authorizedIp){
-         $this->maintenance = $maintenance;
-         $this->twig = $twig;
-         $this->authorizedIp = $authorizedIp;
-     }
- 
-     public function onKernelRequest(RequestEvent $event){
-         $userIp = $event->getRequest()->getClientIp();
-         
-         //if(!file_exists($this->maintenance) || $userIp == self::AUTHORIZED_IP){
-         if(!file_exists($this->maintenance) || $userIp == $this->authorizedIp){
-             return;
-         }
- 
- 
-         $event->setResponse(
-             new Response(
-                 $this->twig->render('maintenance/index.html.twig',
-                 [
-                     'title_meta' => 'Site en maintenance',
-                     'page' => 'maintenance',
-                 ]),
-                 Response::HTTP_SERVICE_UNAVAILABLE
-             )
-         );
-         $event->stopPropagation();
-     }
- 
- }