src/EventSubscriber/RequestSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. namespace App\EventSubscriber;
  3. use Exception;
  4. use App\Controller\Front\SecurityTokenTrait;
  5. use App\Service\ClientService;
  6. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  7. use Symfony\Component\HttpKernel\Event\RequestEvent;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
  10. class RequestSubscriber implements EventSubscriberInterface
  11. {
  12.     use SecurityTokenTrait;
  13.     private ClientService $clientService;
  14.     private TokenStorageInterface $storage;
  15.     public function __construct(ClientService $clientServiceTokenStorageInterface $storage)
  16.     {
  17.         $this->clientService $clientService;
  18.         $this->storage $storage;
  19.     }
  20.     /**
  21.      * @throws Exception
  22.      */
  23.     public function onKernelRequest(RequestEvent $event): void
  24.     {
  25.         if (!$event->isMainRequest()) {
  26.             return;
  27.         }
  28.         $this->validateUser($this->clientService$this->storage);
  29.     }
  30.     public static function getSubscribedEvents(): array
  31.     {
  32.         return [
  33.             'kernel.request' => 'onKernelRequest',
  34.         ];
  35.     }
  36. }