Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed Request management for RequestListener

  • Loading branch information...
commit a7b2b7e92b5ce3e234464d47ee3b5cbfa41a55ed 1 parent 0892135
@fabpot fabpot authored
View
1  src/Symfony/Bundle/FrameworkBundle/Resources/config/routing.xml
@@ -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>
View
22 src/Symfony/Component/HttpKernel/EventListener/RouterListener.php
@@ -23,6 +23,7 @@
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 @@ public function __construct($matcher, RequestContext $context = null, LoggerInte
$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
Please sign in to comment.
Something went wrong with that request. Please try again.