src/EventSubscriber/LocaleSubscriber.php line 32

Open in your IDE?
  1. <?php
  2. /**
  3.  * Created by IntelliJ IDEA.
  4.  * User: dogukan
  5.  * Date: 2019-02-25
  6.  * Time: 22:07
  7.  */
  8. namespace App\EventSubscriber;
  9. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  10. use Symfony\Component\HttpKernel\Event\GetResponseEvent;
  11. use Symfony\Component\HttpKernel\KernelEvents;
  12. class LocaleSubscriber implements EventSubscriberInterface
  13. {
  14.     /**
  15.      * {@inheritdoc}
  16.      */
  17.     public static function getSubscribedEvents()
  18.     {
  19.         return [
  20.             KernelEvents::REQUEST => [ 'setLocale'17 ]
  21.         ];
  22.     }
  23.     /**
  24.      * @param GetResponseEvent $event
  25.      */
  26.     public function setLocale(GetResponseEvent $event)
  27.     {
  28.         $request $event->getRequest();
  29.         if (null !== $locale $request->getPreferredLanguage()) {
  30.             $request->setLocale($locale);
  31.         }
  32.     }
  33. }