Skip to content

Commit 117ed8f

Browse files
committed
[#15186] Update example
1 parent 4648d02 commit 117ed8f

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

security.rst

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,13 +1771,18 @@ to execute custom logic::
17711771
// src/EventListener/LogoutSubscriber.php
17721772
namespace App\EventListener;
17731773

1774-
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
17751774
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
17761775
use Symfony\Component\HttpFoundation\RedirectResponse;
1776+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
17771777
use Symfony\Component\Security\Http\Event\LogoutEvent;
17781778

1779-
class LogoutSubscriber extends AbstractController implements EventSubscriberInterface
1779+
class LogoutSubscriber implements EventSubscriberInterface
17801780
{
1781+
public function __construct(
1782+
private UrlGeneratorInterface $urlGenerator
1783+
) {
1784+
}
1785+
17811786
public static function getSubscribedEvents(): array
17821787
{
17831788
return [LogoutEvent::class => 'onLogout'];
@@ -1794,10 +1799,12 @@ to execute custom logic::
17941799
// get the current response, if it is already set by another listener
17951800
$response = $event->getResponse();
17961801

1797-
// configure a custom logout response
1798-
$event->setResponse(
1799-
new RedirectResponse($this->generateUrl('homepage', []), RedirectResponse::HTTP_SEE_OTHER)
1802+
// configure a custom logout response to the homepage
1803+
$response = new RedirectResponse(
1804+
$this->urlGenerator->generate('homepage'),
1805+
RedirectResponse::HTTP_SEE_OTHER
18001806
);
1807+
$event->setResponse($response);
18011808
}
18021809
}
18031810

0 commit comments

Comments
 (0)