<?php
namespace App\Listener;
use App\Controller\ApiV2\AbstractController;
use App\Helpers\ApiLogger;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Event\ControllerEvent;
class ApiLoggerListener
{
public function onKernelController(ControllerEvent $event): void
{
$controller = $event->getController();
if (!is_object($controller) && $controller[0] instanceof AbstractController) {
$request = $event->getRequest();
$xAuthToken = $request->headers->get('Authorization') ?? null;
$content = json_decode($request->getContent(), true);
ApiLogger::encryptPassword($content);
$array = [
'date' => date('Y-m-d H:j:s'),
'action' => $request->getRequestUri(),
'x-auth-token' => $xAuthToken,
'body' => $content,
'method' => $request->getMethod(),
'ip' => $request->getClientIp(),
'host' => $request->getHost(),
'serverName' => $request->server->get('SERVER_NAME')
];
try {
ApiLogger::addApiLog($array);
} catch (\Exception $e) {
}
}
}
}