Created
May 4, 2016 01:10
-
-
Save miguelplazasr/ba5fef50c0af9db90c27e124a70bba72 to your computer and use it in GitHub Desktop.
Listener for set locale session by profile user
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 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