4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\HttpKernel\EventListener;
14 use Symfony\Component\HttpFoundation\Session\SessionInterface;
15 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
16 use Symfony\Component\HttpKernel\KernelEvents;
17 use Symfony\Component\EventDispatcher\EventSubscriberInterface;
20 * Sets the session in the request.
22 * @author Johannes M. Schmitt <schmittjoh@gmail.com>
24 abstract class SessionListener implements EventSubscriberInterface
26 public function onKernelRequest(GetResponseEvent $event)
28 if (!$event->isMasterRequest()) {
32 $request = $event->getRequest();
33 $session = $this->getSession();
34 if (null === $session || $request->hasSession()) {
38 $request->setSession($session);
41 public static function getSubscribedEvents()
44 KernelEvents::REQUEST => array('onKernelRequest', 128),
49 * Gets the session object.
51 * @return SessionInterface|null A SessionInterface instance or null if no session is available
53 abstract protected function getSession();