Skip to content

Commit a7b2b7e

Browse files
committed
fixed Request management for RequestListener
1 parent 0892135 commit a7b2b7e

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@
9494
<argument type="service" id="router" />
9595
<argument type="service" id="router.request_context" on-invalid="ignore" />
9696
<argument type="service" id="logger" on-invalid="ignore" />
97+
<call method="setRequest"><argument type="service" id="request" on-invalid="null" strict="false" /></call>
9798
</service>
9899
</services>
99100
</container>

src/Symfony/Component/HttpKernel/EventListener/RouterListener.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Symfony\Component\Routing\RequestContext;
2424
use Symfony\Component\Routing\RequestContextAwareInterface;
2525
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
26+
use Symfony\Component\HttpFoundation\Request;
2627

2728
/**
2829
* Initializes the context from the request and sets request attributes based on a matching route.
@@ -59,12 +60,31 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
5960
$this->logger = $logger;
6061
}
6162

63+
/**
64+
* Sets the current Request.
65+
*
66+
* The application should call this method whenever the Request
67+
* object changes (entering a Request scope for instance, but
68+
* also when leaving a Request scope -- especially when they are
69+
* nested).
70+
*
71+
* @param Request|null $request A Request instance
72+
*/
73+
public function setRequest(Request $request = null)
74+
{
75+
if (null !== $request) {
76+
$this->context->fromRequest($request);
77+
}
78+
}
79+
6280
public function onKernelRequest(GetResponseEvent $event)
6381
{
6482
$request = $event->getRequest();
6583

6684
// initialize the context that is also used by the generator (assuming matcher and generator share the same context instance)
67-
$this->context->fromRequest($request);
85+
// we call setRequest even if most of the time, it has already been done to keep compatibility
86+
// with frameworks which do not use the Symfony service container
87+
$this->setRequest($request);
6888

6989
if ($request->attributes->has('_controller')) {
7090
// routing is already done

0 commit comments

Comments
 (0)