Skip to content

Instantly share code, notes, and snippets.

@miguelplazasr
Created May 4, 2016 01:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelplazasr/ba5fef50c0af9db90c27e124a70bba72 to your computer and use it in GitHub Desktop.
Save miguelplazasr/ba5fef50c0af9db90c27e124a70bba72 to your computer and use it in GitHub Desktop.
Listener for set locale session by profile user
<?php
namespace AppBundle\EventListener;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
class UserLocaleListener
{
/**
* @var Session
*/
private $session;
public function __construct(Session $session)
{
$this->session = $session;
}
/**
* @param InteractiveLoginEvent $event
*/
public function onInteractiveLogin(InteractiveLoginEvent $event)
{
$user = $event->getAuthenticationToken()->getUser();
if (null !== $user->getLocale()) {
$this->session->set('_locale', $user->getLocale());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment