Skip to content

Instantly share code, notes, and snippets.

@bendavies
Created November 25, 2013 15:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bendavies/7642636 to your computer and use it in GitHub Desktop.
Save bendavies/7642636 to your computer and use it in GitHub Desktop.
<?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