vendor/symfony/security-bundle/EventListener/FirewallListener.php line 50

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Symfony package.
  4.  *
  5.  * (c) Fabien Potencier <[email protected]>
  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\EventListener;
  11. use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
  12. use Symfony\Component\HttpKernel\Event\FinishRequestEvent;
  13. use Symfony\Component\HttpKernel\Event\RequestEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. use Symfony\Component\Security\Http\Firewall;
  16. use Symfony\Component\Security\Http\FirewallMapInterface;
  17. use Symfony\Component\Security\Http\Logout\LogoutUrlGenerator;
  18. use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
  19. /**
  20.  * @author Maxime Steinhausser <[email protected]>
  21.  */
  22. class FirewallListener extends Firewall
  23. {
  24.     private $map;
  25.     private $logoutUrlGenerator;
  26.     public function __construct(FirewallMapInterface $mapEventDispatcherInterface $dispatcherLogoutUrlGenerator $logoutUrlGenerator)
  27.     {
  28.         $this->map $map;
  29.         $this->logoutUrlGenerator $logoutUrlGenerator;
  30.         parent::__construct($map$dispatcher);
  31.     }
  32.     public function configureLogoutUrlGenerator(RequestEvent $event)
  33.     {
  34.         if (!$event->isMainRequest()) {
  35.             return;
  36.         }
  37.         if ($this->map instanceof FirewallMap && $config $this->map->getFirewallConfig($event->getRequest())) {
  38.             $this->logoutUrlGenerator->setCurrentFirewall($config->getName(), $config->getContext());
  39.         }
  40.     }
  41.     public function onKernelFinishRequest(FinishRequestEvent $event)
  42.     {
  43.         if ($event->isMainRequest()) {
  44.             $this->logoutUrlGenerator->setCurrentFirewall(null);
  45.         }
  46.         parent::onKernelFinishRequest($event);
  47.     }
  48.     /**
  49.      * {@inheritdoc}
  50.      */
  51.     public static function getSubscribedEvents()
  52.     {
  53.         return [
  54.             KernelEvents::REQUEST => [
  55.                 ['configureLogoutUrlGenerator'8],
  56.                 ['onKernelRequest'8],
  57.             ],
  58.             KernelEvents::FINISH_REQUEST => 'onKernelFinishRequest',
  59.         ];
  60.     }
  61. }