[WebBundle] re-organized the sub-request management a bit (WIP)
This commit is contained in:
parent
72947d8588
commit
bb77e9a3d6
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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');
|
||||
|
Reference in New Issue
Block a user