/
LegacyLogoutHandlerListener.php
52 lines (44 loc) · 1.74 KB
/
LegacyLogoutHandlerListener.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Http\Event\LogoutEvent;
use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
/**
* @author Wouter de Jong <wouter@wouterj.nl>
*
* @internal
*/
class LegacyLogoutHandlerListener implements EventSubscriberInterface
{
private $logoutHandler;
public function __construct(object $logoutHandler)
{
if (!$logoutHandler instanceof LogoutSuccessHandlerInterface && !$logoutHandler instanceof LogoutHandlerInterface) {
throw new \InvalidArgumentException(sprintf('An instance of "%s" or "%s" must be passed to "%s", "%s" given.', LogoutHandlerInterface::class, LogoutSuccessHandlerInterface::class, __METHOD__, get_debug_type($logoutHandler)));
}
$this->logoutHandler = $logoutHandler;
}
public function onLogout(LogoutEvent $event): void
{
if ($this->logoutHandler instanceof LogoutSuccessHandlerInterface) {
$event->setResponse($this->logoutHandler->onLogoutSuccess($event->getRequest()));
} elseif ($this->logoutHandler instanceof LogoutHandlerInterface) {
$this->logoutHandler->logout($event->getRequest(), $event->getResponse(), $event->getToken());
}
}
public static function getSubscribedEvents(): array
{
return [
LogoutEvent::class => 'onLogout',
];
}
}