src/App/Controller/DefaultController.php line 17

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