From 72947d85880adf31ceb6f6d65b78644ae1761a9b Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Thu, 13 May 2010 08:15:37 +0200 Subject: [PATCH] re-organized the sub-request management a bit (WIP) --- src/Symfony/Foundation/Kernel.php | 12 ++++++++---- src/Symfony/Framework/WebBundle/Controller.php | 4 ++-- .../WebBundle/Listener/ControllerLoader.php | 10 ++-------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/Symfony/Foundation/Kernel.php b/src/Symfony/Foundation/Kernel.php index bdc0d6d17a7c..60d3fa337621 100644 --- a/src/Symfony/Foundation/Kernel.php +++ b/src/Symfony/Foundation/Kernel.php @@ -161,7 +161,7 @@ public function getRequest() } /** - * Handles a request to convert it to a response by calling the Request Handler service. + * Handles a request to convert it to a response by calling the HttpKernel service. * * @param Request $request A Request instance * @param Boolean $main Whether this is the main request or not @@ -177,15 +177,19 @@ public function handle(Request $request = null, $main = true, $raw = false) if (null === $request) { $request = $this->container->getRequestService(); - } else { - $this->container->setService('request', $request); } if (true === $main) { $this->request = $request; } - return $this->container->getHttpKernelService()->handle($request, $main, $raw); + $this->container->setService('request', $request); + + $response = $this->container->getHttpKernelService()->handle($request, $main, $raw); + + $this->container->setService('request', $this->request); + + return $response; } public function getBundleDirs() diff --git a/src/Symfony/Framework/WebBundle/Controller.php b/src/Symfony/Framework/WebBundle/Controller.php index d284612d9f4f..59695de92a2c 100644 --- a/src/Symfony/Framework/WebBundle/Controller.php +++ b/src/Symfony/Framework/WebBundle/Controller.php @@ -82,9 +82,9 @@ public function generateUrl($route, array $parameters = array(), $absolute = fal return $this->container->getRouterService()->generate($route, $parameters); } - public function forward($controller, array $parameters = array()) + public function forward($controller, array $path = array(), array $query = array()) { - return $this->container->getControllerLoaderService()->run($controller, $parameters); + return $this->container->getControllerLoaderService()->run($controller, $path, $query); } /** diff --git a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php index 34f598eaf70f..ff1025c34e55 100644 --- a/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php +++ b/src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php @@ -41,17 +41,11 @@ public function register() public function run($controller, array $path = array(), array $query = array()) { - $request = $this->container->getRequestService(); - $path['_controller'] = $controller; - $subRequest = $request->duplicate($query, null, $path); - - $response = $this->container->getKernelService()->handle($subRequest, false, true); - - $this->container->setService('request', $request); + $subRequest = $this->container->getRequestService()->duplicate($query, null, $path); - return $response; + return $this->container->getKernelService()->handle($subRequest, false, true); } public function resolve(Event $event)