src/FMT/Domain/Listener/RequestListener.php line 22

Open in your IDE?
  1. <?php
  2. namespace FMT\Domain\Listener;
  3. use Symfony\Component\HttpFoundation\RedirectResponse;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\Event\ResponseEvent;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Symfony\Component\Security\Core\Security;
  8. class RequestListener
  9. {
  10.     private Security $security;
  11.     private UrlGeneratorInterface $router;
  12.     public function __construct(Security $securityUrlGeneratorInterface $router)
  13.     {
  14.         $this->security $security;
  15.         $this->router $router;
  16.     }
  17.     public function onKernelResponse(ResponseEvent $event)
  18.     {
  19.         $response $event->getResponse();
  20.         $response->headers->set("Vary""Cookie");
  21.     }
  22.     public function onKernelRequest(RequestEvent $event)
  23.     {
  24.         $user $this->security->getUser();
  25.         if ($user === null) {
  26.             return;
  27.         }
  28.         if ($user->isUserBlocked()) {
  29.             $url $this->router->generate('logout_manual');
  30.             $event->setResponse(new RedirectResponse($url));
  31.         }
  32.     }
  33. }