src/EventSubscriber/Log/LogPostSerializerSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: SUSAN MEDINA
  5.  * Date: 08/09/2019
  6.  * Time: 11:33 AM
  7.  */
  8. namespace App\EventSubscriber\Log;
  9. use App\Services\LogService;
  10. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  11. use Symfony\Component\HttpKernel\Event\ViewEvent;
  12. use ApiPlatform\Core\EventListener\EventPriorities;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. class LogPostSerializerSubscriber implements EventSubscriberInterface
  15. {
  16.     private $logService;
  17.     public function __construct(LogService $logService)
  18.     {
  19.         $this->logService $logService;
  20.     }
  21.     /**
  22.      * @param ViewEvent $event
  23.      */
  24.     public function onKernelView(ViewEvent $event)
  25.     {
  26.         $request $event->getRequest();
  27.         $logResult $event->getControllerResult();
  28.         $routes = array('api_log_entries_get_collection');
  29.         $route $request->attributes->get('_route');
  30.         if (!in_array($route$routes)) {
  31.             return;
  32.         }
  33.         $logResult json_decode($logResulttrue);
  34.         foreach ($logResult as &$log) {
  35.             $log $this->logService->formatNormalize($log);
  36.         }
  37.         $logResult json_encode($logResult);
  38.         $event->setControllerResult($logResult);
  39.     }
  40.     public static function getSubscribedEvents()
  41.     {
  42.         return [
  43.             KernelEvents::VIEW => ['onKernelView'EventPriorities::POST_SERIALIZE]
  44.         ];
  45.     }
  46. }