LocaleListener
class LocaleListener implements EventSubscriberInterface
Initializes the locale based on the current request.
This listener works in 2 modes:
- 2.3 compatibility mode where you must call setRequest whenever the Request changes.
- 2.4+ mode where you must pass a RequestStack instance in the constructor.
Methods
__construct(RequestStack $requestStack = null, string $defaultLocale = 'en', RequestContextAwareInterface|null $router = null) RequestStack will become required in 3.0. | ||
setRequest(Request $request = null) deprecated Sets the current Request. | ||
onKernelRequest(GetResponseEvent $event) | ||
onKernelFinishRequest(FinishRequestEvent $event) | ||
static array | getSubscribedEvents() Returns an array of event names this subscriber wants to listen to. |
Details
__construct(RequestStack $requestStack = null, string $defaultLocale = 'en', RequestContextAwareInterface|null $router = null)
RequestStack will become required in 3.0.
Parameters
RequestStack | $requestStack | A RequestStack instance |
string | $defaultLocale | The default locale |
RequestContextAwareInterface|null | $router | The router |
Exceptions
InvalidArgumentException |
setRequest(Request $request = null) deprecated
deprecated
Sets the current Request.
This method was used to synchronize the Request, but as the HttpKernel is doing that automatically now, you should never call it directly. It is kept public for BC with the 2.3 version.
Parameters
Request | $request | A Request instance |
onKernelRequest(GetResponseEvent $event)
Parameters
GetResponseEvent | $event |
onKernelFinishRequest(FinishRequestEvent $event)
Parameters
FinishRequestEvent | $event |
static array getSubscribedEvents()
Returns an array of event names this subscriber wants to listen to.
The array keys are event names and the value can be:
- The method name to call (priority defaults to 0)
- An array composed of the method name to call and the priority
- An array of arrays composed of the method names to call and respective priorities, or 0 if unset
For instance:
- array('eventName' => 'methodName')
- array('eventName' => array('methodName', $priority))
- array('eventName' => array(array('methodName1', $priority), array('methodName2')))
Return Value
array | The event names to listen to |
© 2004–2017 Fabien Potencier
Licensed under the MIT License.
http://api.symfony.com/2.8/Symfony/Component/HttpKernel/EventListener/LocaleListener.html