src/Controller/MonitoringAction.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\EventListener\RequestListener;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\JsonResponse;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class MonitoringAction extends AbstractController
  8. {
  9.     /**
  10.      * @Route("/api/monitoring")
  11.      *
  12.      * @return void
  13.      */
  14.     public function checkIsMaintenance(): JsonResponse
  15.     {
  16.         if (in_array($this->getIPClient(), RequestListener::MAINTENANCE_IPStrue)) {
  17.             return new JsonResponse([
  18.                 'isMaintenance' => false,
  19.             ]);
  20.         }
  21.         return new JsonResponse([
  22.             'isMaintenance' => isset($_SERVER['IS_MAINTENANCE']) && 'true' === $_SERVER['IS_MAINTENANCE'],
  23.         ]);
  24.     }
  25.     /**
  26.      * Retourne l'IP Public du Client.
  27.      * Le cas d'un proxy devant le serveur web est géré.
  28.      *
  29.      * @return string
  30.      */
  31.     public function getIPClient()
  32.     {
  33.         return $_SERVER['HTTP_CF_CONNECTING_IP']
  34.             ?? $_SERVER['HTTP_CLIENT_IP']
  35.             ?? $_SERVER['HTTP_X_FORWARDED_FOR']
  36.             ?? $_SERVER['REMOTE_ADDR']
  37.             ?? '127.0.0.1'
  38.             ;
  39.     }
  40. }