浏览代码

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

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

+ 13 - 1
src/Symfony/Framework/WebBundle/Controller.php

@@ -82,9 +82,21 @@ class Controller
         return $this->container->getRouterService()->generate($route, $parameters);
     }
 
+    /**
+     * Forwards the request to another controller.
+     *
+     * @param  string  $controller The controller name (a string like BlogBundle:Post:index)
+     * @param  array   $path       An array of path parameters
+     * @param  array   $query      An array of query parameters
+     *
+     * @return Response A Response instance
+     */
     public function forward($controller, array $path = array(), array $query = array())
     {
-        return $this->container->getControllerLoaderService()->run($controller, $path, $query);
+        $path['_controller'] = $controller;
+        $subRequest = $this->getRequest()->duplicate($query, null, $path);
+
+        return $this->container->getKernelService()->handle($subRequest, false, true);
     }
 
     /**

+ 25 - 6
src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php

@@ -36,14 +36,33 @@ class ActionsHelper extends Helper
         $this->container = $container;
     }
 
-    public function output($controller, array $parameters = array())
-    {
-        echo $this->render($controller, $parameters);
-    }
+    /**
+     * Outputs the Response content for a given controller.
+     *
+     * @param string $controller A controller name to execute (a string like BlogBundle:Post:index)
+     * @param array  $path       An array of path parameters
+     * @param array  $query      An array of query parameters
+     *
+     * @see render()
+     */
+     public function output($controller, array $path = array(), array $query = array())
+     {
+         echo $this->render($controller, $path, $query);
+     }
 
-    public function render($controller, array $parameters = array())
+    /**
+     * Returns the Response content for a given controller.
+     *
+     * @param string $controller A controller name to execute (a string like BlogBundle:Post:index)
+     * @param array  $path       An array of path parameters
+     * @param array  $query      An array of query parameters
+     */
+    public function render($controller, array $path = array(), array $query = array())
     {
-        return $this->container->getControllerLoaderService()->run($controller, Escaper::unescape($parameters))->getContent();
+        $path['_controller'] = $controller;
+        $subRequest = $this->container->getRequestService()->duplicate($query, null, Escaper::unescape($path));
+
+        return $this->container->getKernelService()->handle($subRequest, false, true);
     }
 
     /**

+ 0 - 9
src/Symfony/Framework/WebBundle/Listener/ControllerLoader.php

@@ -39,15 +39,6 @@ class ControllerLoader
         $this->container->getEventDispatcherService()->connect('core.load_controller', array($this, 'resolve'));
     }
 
-    public function run($controller, array $path = array(), array $query = array())
-    {
-        $path['_controller'] = $controller;
-
-        $subRequest = $this->container->getRequestService()->duplicate($query, null, $path);
-
-        return $this->container->getKernelService()->handle($subRequest, false, true);
-    }
-
     public function resolve(Event $event)
     {
         $request = $event->getParameter('request');