namespace Symfony\Component\HttpKernel\EventListener;
-use Symfony\Component\HttpFoundation\Session\SessionInterface;
-use Symfony\Component\HttpKernel\Event\GetResponseEvent;
-use Symfony\Component\HttpKernel\KernelEvents;
-use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Psr\Container\ContainerInterface;
/**
* Sets the session in the request.
*
- * @author Johannes M. Schmitt <schmittjoh@gmail.com>
+ * @author Fabien Potencier <fabien@symfony.com>
+ *
+ * @final since version 3.3
*/
-abstract class SessionListener implements EventSubscriberInterface
+class SessionListener extends AbstractSessionListener
{
- public function onKernelRequest(GetResponseEvent $event)
+ private $container;
+
+ public function __construct(ContainerInterface $container)
{
- if (!$event->isMasterRequest()) {
- return;
- }
+ $this->container = $container;
+ }
- $request = $event->getRequest();
- $session = $this->getSession();
- if (null === $session || $request->hasSession()) {
+ protected function getSession()
+ {
+ if (!$this->container->has('session')) {
return;
}
- $request->setSession($session);
+ return $this->container->get('session');
}
-
- public static function getSubscribedEvents()
- {
- return array(
- KernelEvents::REQUEST => array('onKernelRequest', 128),
- );
- }
-
- /**
- * Gets the session object.
- *
- * @return SessionInterface|null A SessionInterface instance or null if no session is available
- */
- abstract protected function getSession();
}