From 8fe25d343bea218b41894be02740a9247b421975 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 3 May 2010 11:17:02 +0200 Subject: [PATCH] [WebBundle] made the request instance explicit in the controller base class (useful if you inject the request for testing purpose) --- src/Symfony/Framework/WebBundle/Controller.php | 14 +++++++++++++- .../WebBundle/Listener/ControllerLoader.php | 1 + 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Symfony/Framework/WebBundle/Controller.php b/src/Symfony/Framework/WebBundle/Controller.php index 75fe3384f7..d23ad2a097 100644 --- a/src/Symfony/Framework/WebBundle/Controller.php +++ b/src/Symfony/Framework/WebBundle/Controller.php @@ -3,6 +3,7 @@ namespace Symfony\Framework\WebBundle; use Symfony\Components\DependencyInjection\ContainerInterface; +use Symfony\Components\RequestHandler\Request; use Symfony\Components\RequestHandler\Response; /* @@ -24,6 +25,7 @@ use Symfony\Components\RequestHandler\Response; class Controller { protected $container; + protected $request; function __construct(ContainerInterface $container) { @@ -32,7 +34,17 @@ class Controller public function getRequest() { - return $this->container->getRequestService(); + if (null === $this->request) + { + $this->request = $this->container->getRequestService(); + } + + return $this->request; + } + + public function setRequest(Request $request) + { + return $this->request = $request; } public function getUser() diff --git a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php index ae0a94403f..76127507b4 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php +++ b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php @@ -69,6 +69,7 @@ class ControllerLoader } $controller = $this->findController($bundle, $controller, $action); + $controller[0]->setRequest($request); $r = new \ReflectionObject($controller[0]); $arguments = $this->getMethodArguments($r->getMethod($controller[1]), $event->getParameter('request')->path->all(), sprintf('%s::%s()', get_class($controller[0]), $controller[1]));