src/Hitso/Bundle/MultiSiteBundle/EventListener/GraphQlLocaleSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Hitso\Bundle\MultiSiteBundle\EventListener;
  4. use Hitso\Bundle\MultiSiteBundle\MultiSite\SiteContext;
  5. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  6. use Symfony\Component\HttpKernel\Event\RequestEvent;
  7. use Symfony\Component\HttpKernel\KernelEvents;
  8. class GraphQlLocaleSubscriber implements EventSubscriberInterface
  9. {
  10.     /**
  11.      * @var SiteContext
  12.      */
  13.     protected $context;
  14.     public function __construct(SiteContext $context)
  15.     {
  16.         $this->context $context;
  17.     }
  18.     public static function getSubscribedEvents()
  19.     {
  20.         return [
  21.             KernelEvents::REQUEST => [
  22.                 ['onKernelRequest'190],
  23.             ],
  24.         ];
  25.     }
  26.     public function onKernelRequest(RequestEvent $event)
  27.     {
  28.         $request $event->getRequest();
  29.         if (!in_array($request->getPathInfo(), ['/graphql']) || !$request->headers->has('locale')) {
  30.             return;
  31.         }
  32.         $locale $request->headers->get('locale');
  33. //        $request->setLocale($locale);
  34. //        $request->setDefaultLocale($locale);
  35.         $this->context->getContentSite()->setLocale($locale);
  36.         $this->context->getRunningSite()->setLocale($locale);
  37.     }
  38. }