src/Core/EventSubscriber/RouteHistorySubscriber.php line 31

  1. <?php
  2. namespace App\Core\EventSubscriber;
  3. use App\Core\Service\RouteHistoryInterface;
  4. use JetBrains\PhpStorm\ArrayShape;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class RouteHistorySubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var RouteHistoryInterface
  12.      */
  13.     private $routeHistory;
  14.     public function __construct(RouteHistoryInterface $routeHistory)
  15.     {
  16.         $this->routeHistory $routeHistory;
  17.     }
  18.     #[ArrayShape([KernelEvents::REQUEST => 'string'])]
  19.     public static function getSubscribedEvents(): array
  20.     {
  21.         return [
  22.             KernelEvents::REQUEST => 'onKernelRequest',
  23.         ];
  24.     }
  25.     public function onKernelRequest(RequestEvent $event)
  26.     {
  27.         if (false === $event->isMainRequest()) {
  28.             return;
  29.         }
  30.         $this->routeHistory->processRequest($event->getRequest());
  31.     }
  32. }