src/TransBundle/Listener/LocaleListener.php line 18

Open in your IDE?
  1. <?php
  2. namespace TransBundle\Listener;
  3. use Symfony\Component\DependencyInjection\ContainerInterface;
  4. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  5. use Symfony\Component\HttpKernel\HttpKernelInterface;
  6. class LocaleListener
  7. {
  8.     private $container;
  9.     public function __construct(ContainerInterface $container)
  10.     {
  11.         $this->container $container;
  12.     }
  13.     public function onKernelRequest(GetResponseEvent $event)
  14.     {
  15.         if (HttpKernelInterface::MASTER_REQUEST !== $event->getRequestType()) {
  16.             return;
  17.         }
  18.         $request $event->getRequest();
  19.         $route $request->attributes->get('_route');
  20.         if (substr($route01) == '_'  || in_array($this->container->getParameter("kernel.environment"), ['docker_admin''dev_admin''prod_admin'])) {
  21.             $request->setLocale('ru');
  22.             $this->container->get('translator')->setLocale('ru');
  23.             return;
  24.         }
  25.         if ($locale $request->cookies->get($this->container->getParameter('lang_cookie_name'))) {
  26.             $request->setLocale($locale);
  27.         } else if ($locale $request->getSession()->get('_locale')) {
  28.             $request->setLocale($locale);
  29.         }
  30.         if ($locale $request->get("site_checker_api_language")) {
  31.             $request->setLocale($locale);
  32.         } else if ($locale $request->getSession()->get('_locale')) {
  33.             $request->setLocale($locale);
  34.         }
  35.     }
  36. }