RouterListener

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)
onKernelRequest(GetResponseEvent $event)
static array getSubscribedEvents()

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

Details

__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

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

onKernelFinishRequest(FinishRequestEvent $event)

Parameters

FinishRequestEvent $event

onKernelRequest(GetResponseEvent $event)

Parameters

GetResponseEvent $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.7/Symfony/Component/HttpKernel/EventListener/RouterListener.html