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)

No description

onKernelFinishRequest(FinishRequestEvent $event)

No description

static array
getSubscribedEvents()

Returns an array of event names this subscriber wants to listen to.

Details

at line 47
__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

at line 83
setRequest(Request $request = null) deprecated

deprecated since version 2.4, to be removed in 3.0.

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

at line 95
onKernelRequest(GetResponseEvent $event)

Parameters

GetResponseEvent $event

at line 104
onKernelFinishRequest(FinishRequestEvent $event)

Parameters

FinishRequestEvent $event

at line 129
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