for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
declare(strict_types=1);
/*
* This file is part of the Sonata Project package.
*
* (c) Thomas Rabaix <[email protected]>
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Sonata\TranslationBundle\EventSubscriber;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
use Symfony\Component\Security\Http\SecurityEvents;
/**
* Stores the locale of the user in the session after the
* login. This can be used by the LocaleSubscriber afterwards.
* @author Jonathan Vautrin <[email protected]>
final class UserLocaleSubscriber implements EventSubscriberInterface
{
* @var SessionInterface
private $session;
* @param SessionInterface $session
public function __construct(SessionInterface $session)
$this->session = $session;
}
* @param InteractiveLoginEvent $event
public function onInteractiveLogin(InteractiveLoginEvent $event): void
$user = $event->getAuthenticationToken()->getUser();
if (null !== $user->getLocale()) {
$this->session->set('_locale', $user->getLocale());
* @return array
public static function getSubscribedEvents()
return [
SecurityEvents::INTERACTIVE_LOGIN => 'onInteractiveLogin',
];