fixed Request management for RequestListener
This commit is contained in:
parent
0892135f45
commit
a7b2b7e92b
@ -94,6 +94,7 @@
|
||||
<argument type="service" id="router" />
|
||||
<argument type="service" id="router.request_context" on-invalid="ignore" />
|
||||
<argument type="service" id="logger" on-invalid="ignore" />
|
||||
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false" /></call>
|
||||
</service>
|
||||
</services>
|
||||
</container>
|
||||
|
@ -23,6 +23,7 @@ use Symfony\Component\Routing\Matcher\RequestMatcherInterface;
|
||||
use Symfony\Component\Routing\RequestContext;
|
||||
use Symfony\Component\Routing\RequestContextAwareInterface;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
|
||||
/**
|
||||
* Initializes the context from the request and sets request attributes based on a matching route.
|
||||
@ -59,12 +60,31 @@ class RouterListener implements EventSubscriberInterface
|
||||
$this->logger = $logger;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current Request.
|
||||
*
|
||||
* The application should call this method whenever the Request
|
||||
* object changes (entering a Request scope for instance, but
|
||||
* also when leaving a Request scope -- especially when they are
|
||||
* nested).
|
||||
*
|
||||
* @param Request|null $request A Request instance
|
||||
*/
|
||||
public function setRequest(Request $request = null)
|
||||
{
|
||||
if (null !== $request) {
|
||||
$this->context->fromRequest($request);
|
||||
}
|
||||
}
|
||||
|
||||
public function onKernelRequest(GetResponseEvent $event)
|
||||
{
|
||||
$request = $event->getRequest();
|
||||
|
||||
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
|
||||
$this->context->fromRequest($request);
|
||||
// we call setRequest even if most of the time, it has already been done to keep compatibility
|
||||
// with frameworks which do not use the Symfony service container
|
||||
$this->setRequest($request);
|
||||
|
||||
if ($request->attributes->has('_controller')) {
|
||||
// routing is already done
|
||||
|
Reference in New Issue
Block a user