src/EventListener/LogoutSubscriber.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\EventListener;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpFoundation\RedirectResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  7. use Symfony\Component\Security\Http\Event\LogoutEvent;
  8. class LogoutSubscriber implements EventSubscriberInterface
  9. {
  10.     private $urlGenerator;
  11.     public function __construct(UrlGeneratorInterface $urlGenerator) {
  12.         $this->urlGenerator $urlGenerator;
  13.     }
  14.     public static function getSubscribedEvents(): array
  15.     {
  16.         return [LogoutEvent::class => 'onLogout'];
  17.     }
  18.     public function onLogout(LogoutEvent $event)
  19.     {
  20.         $request Request::createFromGlobals();
  21.         $clientSlugCookie $request->cookies->get('clientSlug');
  22.         $response = new RedirectResponse(
  23.             $this->urlGenerator->generate('app_main', ['clientSlug' => $clientSlugCookie]),
  24.             RedirectResponse::HTTP_SEE_OTHER
  25.         );
  26.         $event->setResponse($response);
  27.     }
  28. }