src/Listener/LocaleListener.php line 33

Open in your IDE?
  1. <?php
  2. /**
  3.  * This file is part of the pdAdmin package.
  4.  *
  5.  * @package     pd-admin
  6.  * @license     LICENSE
  7.  * @author      Ramazan APAYDIN <apaydin541@gmail.com>
  8.  * @link        https://github.com/appaydin/pd-admin
  9.  */
  10. namespace App\Listener;
  11. use App\Service\ConfigBag;
  12. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  13. use Symfony\Component\HttpKernel\Event\KernelEvent;
  14. use Symfony\Component\HttpKernel\KernelEvents;
  15. /**
  16.  * Change System Default Language.
  17.  *
  18.  * @author Ramazan APAYDIN <apaydin541@gmail.com>
  19.  */
  20. class LocaleListener implements EventSubscriberInterface
  21. {
  22.     private ConfigBag $bag;
  23.     public function __construct(ConfigBag $bag)
  24.     {
  25.         $this->bag $bag;
  26.     }
  27.     public function setDefaultLocale(KernelEvent $event): void
  28.     {
  29.         $event->getRequest()->setDefaultLocale($this->bag->get('default_locale'));
  30.     }
  31.     public static function getSubscribedEvents(): array
  32.     {
  33.         return [KernelEvents::REQUEST => [['setDefaultLocale'99]]];
  34.     }
  35. }