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 39a9dfeffa2657c12c650d0ade9fcd8f0caf24d1 1 parent 8a8b24b
@fabpot fabpot authored
Showing with 21 additions and 1 deletion.
  1. +21 −1 EventListener/RouterListener.php
View
22 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.