src/App/Controller/DefaultController.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Aqarmap\Bundle\UserBundle\Services\Contracts\UserIpInfoServiceInterface;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\HttpKernel\Exception\HttpException;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. class DefaultController extends AbstractController
  12. {
  13.     /**
  14.      * @Route("/health-check/{probeType}", options={"i18n": false})
  15.      */
  16.     public function healthCheck(Request $requeststring $probeTypeEntityManagerInterface $emUserIpInfoServiceInterface $ipInfoService): JsonResponse
  17.     {
  18.         $dbConnected false;
  19.         if ('readiness' == $probeType) {
  20.             // DB Connection Check
  21.             try {
  22.                 $em->getConnection()->connect();
  23.                 $dbConnected $em->getConnection()->isConnected();
  24.             } catch (\Exception $exception) {
  25.                 throw new HttpException(500sprintf('DB Connection Error! (%s)'$exception->getMessage()));
  26.             }
  27.         }
  28.         $date = new \DateTime();
  29.         return $this->json([
  30.             'status' => 'ok',
  31.             'date' => $date->format('r'),
  32.             'db_connection' => $dbConnected,
  33.             'client_ip' => $request->getClientIp(),
  34.         ]);
  35.     }
  36.     /**
  37.      * @Route("/debug", options={"i18n": true})
  38.      */
  39.     public function debug(): Response
  40.     {
  41.         return $this->render('Default/debug.html.twig');
  42.     }
  43. }