for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* (c) FSi sp. z o.o. <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace FSi\Bundle\AdminBundle\EventListener;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
use Symfony\Component\HttpKernel\KernelEvents;
class LocaleListener implements EventSubscriberInterface
{
* @var string
private $defaultLocale;
* @param string $defaultLocale
public function __construct(string $defaultLocale)
$this->defaultLocale = $defaultLocale;
}
public function onKernelRequest(GetResponseEvent $event): void
$request = $event->getRequest();
if (!$request->hasPreviousSession()) {
return;
if ($request->attributes->has('_locale')) {
$request->setLocale($request->getSession()->get('admin_locale', $this->defaultLocale));
public static function getSubscribedEvents(): array
return [KernelEvents::REQUEST => [['onKernelRequest', 17]]];