| Total Complexity | 5 |
| Total Lines | 32 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 18 | class LocaleListener implements EventSubscriberInterface |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | private $defaultLocale; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * @param string $defaultLocale |
||
| 27 | */ |
||
| 28 | public function __construct(string $defaultLocale) |
||
| 29 | { |
||
| 30 | $this->defaultLocale = $defaultLocale; |
||
| 31 | } |
||
| 32 | |||
| 33 | public function onKernelRequest(GetResponseEvent $event): void |
||
| 34 | { |
||
| 35 | $request = $event->getRequest(); |
||
| 36 | if (!$request->hasPreviousSession()) { |
||
| 37 | return; |
||
| 38 | } |
||
| 39 | |||
| 40 | if ($request->attributes->has('_locale')) { |
||
| 41 | return; |
||
| 42 | } |
||
| 43 | |||
| 44 | $request->setLocale($request->getSession()->get('admin_locale', $this->defaultLocale)); |
||
| 45 | } |
||
| 46 | |||
| 47 | public static function getSubscribedEvents(): array |
||
| 50 | } |
||
| 51 | } |
||
| 52 |