environnement complet autonome, révision complete de la méthode, ajout de configuration
This commit is contained in:
36
src/EventListener/LogoutSubscriber.php
Normal file
36
src/EventListener/LogoutSubscriber.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\EventListener;
|
||||
|
||||
use App\Hydra\HydraService;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
|
||||
use Symfony\Component\Security\Http\Event\LogoutEvent;
|
||||
|
||||
class LogoutSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
public function __construct(
|
||||
private UrlGeneratorInterface $urlGenerator,
|
||||
private HydraService $hydra
|
||||
) {
|
||||
}
|
||||
|
||||
public static function getSubscribedEvents(): array
|
||||
{
|
||||
return [LogoutEvent::class => 'onLogout'];
|
||||
}
|
||||
|
||||
public function onLogout(LogoutEvent $event): void
|
||||
{
|
||||
// get the security token of the session that is about to be logged out
|
||||
// get the current request
|
||||
$request = $event->getRequest();
|
||||
|
||||
// get the current response, if it is already set by another listener
|
||||
$response = $event->getResponse();
|
||||
|
||||
// configure a custom logout response to the homepage
|
||||
$response = $this->hydra->handleLogoutRequest($request);
|
||||
$event->setResponse($response);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user