<?php
declare(strict_types=1);
namespace App\Event;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\RequestEvent;
use App\Services\LogoutService;
use App\Entity\User;
class LogoutSubscriber implements EventSubscriberInterface
{
protected LogoutService $logoutService;
public function __construct(LogoutService $logoutService)
{
$this->logoutService = $logoutService;
}
public static function getSubscribedEvents()
{
return [
LogoutEvent::class => 'onLogout',
];
}
public function onLogout(LogoutEvent $event): void
{
$user = $event->getToken()->getUser();
if ($user instanceof User) {
$this->logoutService->userLogout($user);
}
}
}