src/EventSubscriber/Api/ApiSubscriber.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber\Api;
  3. use App\Service\LoggerHelper;
  4. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  5. class ApiSubscriber implements EventSubscriberInterface
  6. {
  7.     /**
  8.      * @var LoggerHelper
  9.      */
  10.     private $loggerHelper;
  11.     /**
  12.      * @param LoggerHelper $loggerHelper
  13.      */
  14.     public function __construct(LoggerHelper $loggerHelper)
  15.     {
  16.         $this->loggerHelper $loggerHelper;
  17.     }
  18.     public function onApiAuthenticate($event)
  19.     {
  20.         $this->loggerHelper->saveMessage(
  21.             'Api',
  22.             $event->getLoggerServiceEntity()[0][0],
  23.             $event->getLoggerServiceEntity()[0][1],
  24.             $event->getLoggerServiceEntity()[1]
  25.         );
  26.     }
  27.     public function onApiResponse($event)
  28.     {
  29.         $context array_values($event->getLoggerServiceEntity()[0]);
  30.         $this->loggerHelper->saveMessage(
  31.             'Api',
  32.             ucfirst(array_keys($event->getLoggerServiceEntity()[0])[0]),
  33.             $context[0],
  34.             $event->getLoggerServiceEntity()[1]
  35.         );
  36.     }
  37.     public static function getSubscribedEvents(): array
  38.     {
  39.         return [
  40.             'api.authenticate' => 'onApiAuthenticate',
  41.             'api.response' => 'onApiResponse',
  42.         ];
  43.     }
  44. }