浏览代码

re-organized the sub-request management a bit (WIP)

Fabien Potencier 15 年之前
父节点
当前提交
72947d8588

+ 8 - 4
src/Symfony/Foundation/Kernel.php

@@ -161,7 +161,7 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
     }
 
     /**
-     * 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 @@ abstract class Kernel implements HttpKernelInterface, \Serializable
 
         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()

+ 2 - 2
src/Symfony/Framework/WebBundle/Controller.php

@@ -82,9 +82,9 @@ class Controller
         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);
     }
 
     /**

+ 2 - 8
src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php

@@ -41,17 +41,11 @@ class ControllerLoader
 
     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)