Skip to content

Commit

Permalink
fixed Request management for RequestListener
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Mar 20, 2013
1 parent 0892135 commit a7b2b7e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
Expand Up @@ -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>
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit a7b2b7e

Please sign in to comment.