vendor/symfony/security-bundle/Security/LegacyLogoutHandlerListener.php line 40

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <fabien@symfony.com>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace Symfony\Bundle\SecurityBundle\Security;
  11. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  12. use Symfony\Component\Security\Http\Event\LogoutEvent;
  13. use Symfony\Component\Security\Http\Logout\LogoutHandlerInterface;
  14. use Symfony\Component\Security\Http\Logout\LogoutSuccessHandlerInterface;
  15. /**
  16.  * @author Wouter de Jong <wouter@wouterj.nl>
  17.  *
  18.  * @internal
  19.  */
  20. class LegacyLogoutHandlerListener implements EventSubscriberInterface
  21. {
  22.     private $logoutHandler;
  23.     public function __construct(object $logoutHandler)
  24.     {
  25.         if (!$logoutHandler instanceof LogoutSuccessHandlerInterface && !$logoutHandler instanceof LogoutHandlerInterface) {
  26.             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)));
  27.         }
  28.         $this->logoutHandler $logoutHandler;
  29.     }
  30.     public function onLogout(LogoutEvent $event): void
  31.     {
  32.         if ($this->logoutHandler instanceof LogoutSuccessHandlerInterface) {
  33.             $event->setResponse($this->logoutHandler->onLogoutSuccess($event->getRequest()));
  34.         } elseif ($this->logoutHandler instanceof LogoutHandlerInterface) {
  35.             $this->logoutHandler->logout($event->getRequest(), $event->getResponse(), $event->getToken());
  36.         }
  37.     }
  38.     public static function getSubscribedEvents(): array
  39.     {
  40.         return [
  41.             LogoutEvent::class => 'onLogout',
  42.         ];
  43.     }
  44. }