Change logout handler to an event listener that listens to LogoutEvent
-use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
-use Symfony\Component\HttpFoundation\Request;
-use Symfony\Component\HttpFoundation\Response;
-use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Symfony\Component\Security\Http\Event\LogoutEvent;
-final class SomeLogoutHandler implements LogoutHandlerInterface
+final class SomeLogoutHandler implements EventSubscriberInterface
{
- public function logout(Request $request, Response $response, TokenInterface $token)
+ public function onLogout(LogoutEvent $logoutEvent): void
{
+ $request = $logoutEvent->getRequest();
+ $response = $logoutEvent->getResponse();
+ $token = $logoutEvent->getToken();
+ }
+
+ /**
+ * @return array<string, string[]>
+ */
+ public static function getSubscribedEvents(): array
+ {
+ return [
+ LogoutEvent::class => ['onLogout'],
+ ];
}
}
Configure your rector.php
:
<?php
use Rector\Config\RectorConfig;
use Rector\Symfony\Symfony51\Rector\Class_\LogoutHandlerToLogoutEventSubscriberRector;
return RectorConfig::configure()
->withRules([
LogoutHandlerToLogoutEventSubscriberRector::class,
]);