<?php
namespace GraphQL\EventListener;
use App\Service\RequestLogManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\ResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LoggingSubscriber implements EventSubscriberInterface
{
private RequestLogManager $requestLogManager;
public function __construct(RequestLogManager $requestLogManager)
{
$this->requestLogManager = $requestLogManager;
}
public static function getSubscribedEvents(): array
{
return [
KernelEvents::RESPONSE => [
['logResponse', 0]
],
];
}
public function logResponse(ResponseEvent $responseEvent): void
{
$this->requestLogManager->saveLog($responseEvent->getRequest(), $responseEvent->getResponse(), 'graphql');
}
}