<?php
namespace App\EventSubscriber\Api;
use App\Service\LoggerHelper;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class ApiSubscriber implements EventSubscriberInterface
{
/**
* @var LoggerHelper
*/
private $loggerHelper;
/**
* @param LoggerHelper $loggerHelper
*/
public function __construct(LoggerHelper $loggerHelper)
{
$this->loggerHelper = $loggerHelper;
}
public function onApiAuthenticate($event)
{
$this->loggerHelper->saveMessage(
'Api',
$event->getLoggerServiceEntity()[0][0],
$event->getLoggerServiceEntity()[0][1],
$event->getLoggerServiceEntity()[1]
);
}
public function onApiResponse($event)
{
$context = array_values($event->getLoggerServiceEntity()[0]);
$this->loggerHelper->saveMessage(
'Api',
ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
$context[0],
$event->getLoggerServiceEntity()[1]
);
}
public static function getSubscribedEvents(): array
{
return [
'api.authenticate' => 'onApiAuthenticate',
'api.response' => 'onApiResponse',
];
}
}