<?php
namespace App\EventSubscriber;
use Exception;
use App\Controller\Front\SecurityTokenTrait;
use App\Service\ClientService;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface;
class RequestSubscriber implements EventSubscriberInterface
{
use SecurityTokenTrait;
private ClientService $clientService;
private TokenStorageInterface $storage;
public function __construct(ClientService $clientService, TokenStorageInterface $storage)
{
$this->clientService = $clientService;
$this->storage = $storage;
}
/**
* @throws Exception
*/
public function onKernelRequest(RequestEvent $event): void
{
if (!$event->isMainRequest()) {
return;
}
$this->validateUser($this->clientService, $this->storage);
}
public static function getSubscribedEvents(): array
{
return [
'kernel.request' => 'onKernelRequest',
];
}
}