vendor/symfony/symfony/src/Symfony/Component/HttpKernel/EventListener/AbstractSessionListener.php line 26

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\Component\HttpKernel\EventListener;
  11. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  12. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  13. use Symfony\Component\HttpKernel\KernelEvents;
  14. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  15. /**
  16.  * Sets the session in the request.
  17.  *
  18.  * @author Johannes M. Schmitt <schmittjoh@gmail.com>
  19.  */
  20. abstract class AbstractSessionListener implements EventSubscriberInterface
  21. {
  22.     public function onKernelRequest(GetResponseEvent $event)
  23.     {
  24.         if (!$event->isMasterRequest()) {
  25.             return;
  26.         }
  27.         $request $event->getRequest();
  28.         $session $this->getSession();
  29.         if (null === $session || $request->hasSession()) {
  30.             return;
  31.         }
  32.         $request->setSession($session);
  33.     }
  34.     public static function getSubscribedEvents()
  35.     {
  36.         return array(
  37.             KernelEvents::REQUEST => array('onKernelRequest'128),
  38.         );
  39.     }
  40.     /**
  41.      * Gets the session object.
  42.      *
  43.      * @return SessionInterface|null A SessionInterface instance or null if no session is available
  44.      */
  45.     abstract protected function getSession();
  46. }