Created
November 25, 2013 15:07
-
-
Save bendavies/7642636 to your computer and use it in GitHub Desktop.
This file contains 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 ...EventListener; | |
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
use Symfony\Component\HttpKernel\HttpKernelInterface; | |
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent; | |
use Symfony\Component\Security\Http\SecurityEvents; | |
class SessionSubscriber implements EventSubscriberInterface | |
{ | |
/** | |
* @param InteractiveLoginEvent $event | |
*/ | |
public function onInteractiveLogin(InteractiveLoginEvent $event) | |
{ | |
$session = $event->getRequest()->getSession(); | |
$id = $event->getAuthenticationToken()->getUser()->getId(); | |
$session->set('user_id', $id); | |
} | |
/** | |
* {@inheritdoc} | |
*/ | |
public static function getSubscribedEvents() | |
{ | |
return [ | |
SecurityEvents::INTERACTIVE_LOGIN => array('onInteractiveLogin'), | |
]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment