Deprecated: Optional parameter $params declared before required parameter $referenceType is implicitly treated as a required parameter in /home/smart-voucher.com/public_html/src/Modules/StoreCart/Service/StoreService.php on line 96
Symfony Profiler

src/EventSubscriber/LocaleSubscriber.php line 31

  1. <?php
  2. namespace App\EventSubscriber;
  3. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  4. use Symfony\Component\HttpKernel\Event\RequestEvent;
  5. use Symfony\Component\HttpKernel\KernelEvents;
  6. use App\Admin\Service\LocaleService as AdminLocaleService;
  7. use App\Service\LocaleService as LocaleService;
  8. class LocaleSubscriber implements EventSubscriberInterface
  9. {
  10.     private $_adminLocaleService;
  11.     private $_localeService;
  12.     public function __construct(
  13.             AdminLocaleService $adminLocaleService,
  14.             LocaleService $localeService)
  15.     {
  16.         $this->_adminLocaleService $adminLocaleService;
  17.         $this->_localeService $localeService;
  18.     }
  19.     public static function getSubscribedEvents()
  20.     {
  21.         return [
  22.             KernelEvents::REQUEST => [['onKernelRequest', -10]]
  23.         ];
  24.     }
  25.     public function onKernelRequest(RequestEvent $event)
  26.     {
  27.         $request $event->getRequest();
  28.         if (/*!$request->hasPreviousSession() || */$request->get('_route') == '')
  29.             return;
  30.         if (strpos($request->get('_route'), 'admin_') === 0)
  31.         {
  32.             $locale $request->getSession()->get('_backend_locale');
  33.             
  34.             if ($locale == '')
  35.             {
  36.                 $clientLocale $this->_getClientLocale();
  37.                 
  38.                 if ($clientLocale != '')
  39.                 {
  40.                     if (in_array($clientLocale$this->_adminLocaleService->getAvailableBackendLocales()))
  41.                         $locale $clientLocale;
  42.                 }
  43.             }
  44.             
  45.             if ($locale == '')
  46.                 $locale $this->_adminLocaleService->getDefaultLocale();
  47.             
  48.             $this->_adminLocaleService->setLocale($locale);
  49.             $this->_adminLocaleService->setContentLocale($this->_adminLocaleService->getContentLocale());
  50.         }
  51.         else
  52.         {
  53.             $locale $request->attributes->get('_locale');
  54.             if ($locale == '')
  55.                 $locale $request->getSession()->get('_locale');
  56.             if ($locale == '')
  57.             {
  58.                 $clientLocale $this->_getClientLocale();
  59.                 
  60.                 if ($clientLocale != '')
  61.                 {
  62.                     if (in_array($clientLocale$this->_localeService->getAvailableLocales()))
  63.                         $locale $clientLocale;
  64.                 }
  65.             }
  66.             
  67.             if ($locale == '')
  68.                 $this->_localeService->getDefaultLocale();
  69.             $this->_localeService->setLocale($locale);
  70.         }
  71.         
  72.     }
  73.     
  74.     private function _getClientLocale()
  75.     {
  76.         if (!empty($_SERVER['HTTP_ACCEPT_LANGUAGE']))
  77.             return strtolower(str_split($_SERVER['HTTP_ACCEPT_LANGUAGE'], 2)[0]);
  78.     }
  79. }