vendor/sylius/sylius/src/Sylius/Bundle/LocaleBundle/Listener/RequestLocaleSetter.php line 38

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the Sylius package.
  4.  *
  5.  * (c) Paweł Jędrzejewski
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. declare(strict_types=1);
  11. namespace Sylius\Bundle\LocaleBundle\Listener;
  12. use Sylius\Component\Locale\Context\LocaleContextInterface;
  13. use Sylius\Component\Locale\Context\LocaleNotFoundException;
  14. use Sylius\Component\Locale\Provider\LocaleProviderInterface;
  15. use Symfony\Component\HttpKernel\Event\RequestEvent;
  16. final class RequestLocaleSetter
  17. {
  18.     private LocaleContextInterface $localeContext;
  19.     private LocaleProviderInterface $localeProvider;
  20.     public function __construct(
  21.         LocaleContextInterface $localeContext,
  22.         LocaleProviderInterface $localeProvider
  23.     ) {
  24.         $this->localeContext $localeContext;
  25.         $this->localeProvider $localeProvider;
  26.     }
  27.     /**
  28.      * @throws LocaleNotFoundException
  29.      */
  30.     public function onKernelRequest(RequestEvent $event): void
  31.     {
  32.         $request $event->getRequest();
  33.         $request->setLocale($this->localeContext->getLocaleCode());
  34.         $request->setDefaultLocale($this->localeProvider->getDefaultLocaleCode());
  35.     }
  36. }