class RouterListener implements EventSubscriberInterface

Initializes the context from the request and sets request attributes based on a matching route.

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(UrlMatcherInterface|RequestMatcherInterface $matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)

RequestStack will become required in 3.0.

setRequest(Request $request = null) deprecated

Sets the current Request.

onKernelFinishRequest(FinishRequestEvent $event)

No description

onKernelRequest(GetResponseEvent $event)

No description

static array
getSubscribedEvents()

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

Details

at line line 59
__construct(UrlMatcherInterface|RequestMatcherInterface $matcher, RequestContext $context = null, LoggerInterface $logger = null, RequestStack $requestStack = null)

RequestStack will become required in 3.0.

Parameters

UrlMatcherInterface|RequestMatcherInterface $matcher The Url or Request matcher
RequestContext $context The RequestContext (can be null when $matcher implements RequestContextAwareInterface)
LoggerInterface $logger The logger
RequestStack $requestStack A RequestStack instance

Exceptions

InvalidArgumentException

at line line 90
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 line 110
onKernelFinishRequest(FinishRequestEvent $event)

Parameters

FinishRequestEvent $event

at line line 119
onKernelRequest(GetResponseEvent $event)

Parameters

GetResponseEvent $event

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