src/Event/LogoutSubscriber.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Event;
  4. use Symfony\Component\Security\Http\Event\LogoutEvent;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use App\Services\LogoutService;
  8. use App\Entity\User;
  9. class LogoutSubscriber implements EventSubscriberInterface
  10. {
  11.     protected LogoutService $logoutService;
  12.     public function __construct(LogoutService $logoutService)
  13.     {
  14.         $this->logoutService $logoutService;
  15.     }
  16.     public static function getSubscribedEvents()
  17.     {
  18.         return [
  19.             LogoutEvent::class => 'onLogout',
  20.         ];
  21.     }
  22.     public function onLogout(LogoutEvent $event): void
  23.     {
  24.         $user $event->getToken()->getUser();
  25.         if ($user instanceof User) {
  26.             $this->logoutService->userLogout($user);
  27.         }
  28.     }
  29. }