Created
January 21, 2015 10:06
-
-
Save rodnaph/4edfaa67878d30894c1e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyApp\MyBundle\Listener; | |
use JMS\DiExtraBundle\Annotation as DI; | |
use Symfony\Component\HttpKernel\Event\GetResponseEvent; | |
use Symfony\Component\HttpKernel\HttpKernelInterface; | |
/** | |
* @DI\Service() | |
* @DI\Tag(name="kernel.event_listener", attributes={"event" = "kernel.request"}) | |
*/ | |
class SessionListener | |
{ | |
/** | |
* @DI\Inject("router") | |
*/ | |
public $router; | |
/** | |
* @DI\Inject("session") | |
*/ | |
public $session; | |
/** | |
* {@inheritDoc} | |
*/ | |
public function onKernelRequest(GetResponseEvent $event) | |
{ | |
if ($event->getRequestType() == HttpKernelInterface::MASTER_REQUEST) { | |
if ($routeName = $event->getRequest()->get('_route')) { | |
$route = $this | |
->router | |
->getRouteCollection() | |
->get($routeName); | |
if ($route) { | |
if (false === $route->getOption('session')) { | |
$this->session->save(); | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment