wallabag/src/Wallabag/CoreBundle/Event/Listener/UserLocaleListener.php

38 lines
921 B
PHP
Raw Normal View History

2015-10-01 14:28:38 +00:00
<?php
namespace Wallabag\CoreBundle\Event\Listener;
2015-10-01 14:28:38 +00:00
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
/**
* Stores the locale of the user in the session after the
* login. This can be used by the LocaleListener afterwards.
2015-10-16 05:40:09 +00:00
*
* @see http://symfony.com/doc/master/cookbook/session/locale_sticky_session.html
2015-10-01 14:28:38 +00:00
*/
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->getConfig()->getLanguage()) {
$this->session->set('_locale', $user->getConfig()->getLanguage());
}
}
}