Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

LocaleListener.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishCoreBundle\EventListener;
8
9 use eZ\Publish\Core\MVC\ConfigResolverInterface;
10 use eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverterInterface;
11 use Symfony\Component\HttpKernel\EventListener\LocaleListener as BaseRequestListener;
12 use Symfony\Component\HttpKernel\Event\GetResponseEvent;
13
17 class LocaleListener extends BaseRequestListener
18 {
20 private $configResolver;
21
23 private $localeConverter;
24
28 public function setConfigResolver(ConfigResolverInterface $configResolver)
29 {
30 $this->configResolver = $configResolver;
31 }
32
36 public function setLocaleConverter(LocaleConverterInterface $localeConverter)
37 {
38 $this->localeConverter = $localeConverter;
39 }
40
41 public function onKernelRequest(GetResponseEvent $event)
42 {
43 $request = $event->getRequest();
44 if (!$request->attributes->has('_locale')) {
45 foreach ($this->configResolver->getParameter('languages') as $locale) {
46 $convertedLocale = $this->localeConverter->convertToPOSIX($locale);
47 if ($convertedLocale !== null) {
48 // Setting the converted locale to the _locale request attribute, so that it can be properly processed by parent listener.
49 $request->attributes->set('_locale', $convertedLocale);
50 break;
51 }
52 }
53 }
54
55 parent::onKernelRequest($event);
56 }
57 }
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener
Enhanced LocaleListener, injecting the converted locale extracted from eZ Publish configuration.
Definition: LocaleListener.php:18
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener\onKernelRequest
onKernelRequest(GetResponseEvent $event)
Definition: LocaleListener.php:41
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener\setConfigResolver
setConfigResolver(ConfigResolverInterface $configResolver)
Definition: LocaleListener.php:28
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener\setLocaleConverter
setLocaleConverter(LocaleConverterInterface $localeConverter)
Definition: LocaleListener.php:36
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener\$localeConverter
$localeConverter
Definition: LocaleListener.php:23
eZ\Bundle\EzPublishCoreBundle\EventListener\LocaleListener\$configResolver
$configResolver
Definition: LocaleListener.php:20
eZ\Publish\Core\MVC\ConfigResolverInterface
Interface for config resolvers.
Definition: ConfigResolverInterface.php:19
eZ\Publish\Core\MVC\Symfony\Locale\LocaleConverterInterface
Interface for locale converters.
Definition: LocaleConverterInterface.php:17
eZ\Bundle\EzPublishCoreBundle\EventListener
Definition: BackgroundIndexingTerminateListener.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.