src/Listener/ApiLoggerListener.php line 12

Open in your IDE?
  1. <?php
  2. namespace App\Listener;
  3. use App\Controller\ApiV2\AbstractController;
  4. use App\Helpers\ApiLogger;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpKernel\Event\ControllerEvent;
  7. class ApiLoggerListener
  8. {
  9.     public function onKernelController(ControllerEvent $event): void
  10.     {
  11.         $controller $event->getController();
  12.         if (!is_object($controller) && $controller[0] instanceof AbstractController) {
  13.             $request $event->getRequest();
  14.             $xAuthToken $request->headers->get('Authorization') ?? null;
  15.             $content json_decode($request->getContent(), true);
  16.             ApiLogger::encryptPassword($content);
  17.             $array = [
  18.                 'date' => date('Y-m-d H:j:s'),
  19.                 'action' => $request->getRequestUri(),
  20.                 'x-auth-token' => $xAuthToken,
  21.                 'body' => $content,
  22.                 'method' => $request->getMethod(),
  23.                 'ip' => $request->getClientIp(),
  24.                 'host' => $request->getHost(),
  25.                 'serverName' => $request->server->get('SERVER_NAME')
  26.             ];
  27.             try {
  28.                 ApiLogger::addApiLog($array);
  29.             } catch (\Exception $e) {
  30.             }
  31.         }
  32.     }
  33. }