TestSessionListener.php in Zircon Profile 8
File
vendor/symfony/http-kernel/EventListener/TestSessionListener.php
View source
<?php
namespace Symfony\Component\HttpKernel\EventListener;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpKernel\KernelEvents;
use Symfony\Component\HttpKernel\Event\FilterResponseEvent;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
abstract class TestSessionListener implements EventSubscriberInterface {
public function onKernelRequest(GetResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$session = $this
->getSession();
if (!$session) {
return;
}
$cookies = $event
->getRequest()->cookies;
if ($cookies
->has($session
->getName())) {
$session
->setId($cookies
->get($session
->getName()));
}
}
public function onKernelResponse(FilterResponseEvent $event) {
if (!$event
->isMasterRequest()) {
return;
}
$session = $event
->getRequest()
->getSession();
if ($session && $session
->isStarted()) {
$session
->save();
$params = session_get_cookie_params();
$event
->getResponse()->headers
->setCookie(new Cookie($session
->getName(), $session
->getId(), 0 === $params['lifetime'] ? 0 : time() + $params['lifetime'], $params['path'], $params['domain'], $params['secure'], $params['httponly']));
}
}
public static function getSubscribedEvents() {
return array(
KernelEvents::REQUEST => array(
'onKernelRequest',
192,
),
KernelEvents::RESPONSE => array(
'onKernelResponse',
-128,
),
);
}
protected abstract function getSession();
}