Skip to content

Commit

Permalink
changed actions::render() helper method signature
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Aug 30, 2010
1 parent 8c47b8a commit 994a6c3
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
Expand Up @@ -79,15 +79,15 @@ protected function createController($controller)
* 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
* @param array $attributes An array of request attributes
* @param array $query An array of request query parameters
*
* @return Response A Response instance
*/
public function forward($controller, array $path = array(), array $query = array())
public function forward($controller, array $attributes = array(), array $query = array())
{
$path['_controller'] = $controller;
$subRequest = $this->container->getRequestService()->duplicate($query, null, $path);
$attributes['_controller'] = $controller;
$subRequest = $this->container->getRequestService()->duplicate($query, null, $attributes);

return $this->container->get('kernel')->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
}
Expand All @@ -100,10 +100,10 @@ public function forward($controller, array $path = array(), array $query = array
*
* Available options:
*
* * path: An array of path parameters (only when the first argument is a controller)
* * query: An array of query parameters (only when the first argument is a controller)
* * attributes: An array of request attributes (only when the first argument is a controller)
* * query: An array of request query parameters (only when the first argument is a controller)
* * ignore_errors: true to return an empty string in case of an error
* * alt: an alternative controller to execute in case of an error (can be a controller, a URI, or an array with the controller, the path arguments, and the query arguments)
* * alt: an alternative controller to execute in case of an error (can be a controller, a URI, or an array with the controller, the attributes, and the query arguments)
* * standalone: whether to generate an esi:include tag or not when ESI is supported
* * comment: a comment to add when returning an esi:include tag
*
Expand All @@ -115,7 +115,7 @@ public function forward($controller, array $path = array(), array $query = array
public function render($controller, array $options = array())
{
$options = array_merge(array(
'path' => array(),
'attributes' => array(),
'query' => array(),
'ignore_errors' => !$this->container->getParameter('kernel.debug'),
'alt' => array(),
Expand All @@ -128,7 +128,7 @@ public function render($controller, array $options = array())
}

if ($this->esiSupport && $options['standalone']) {
$uri = $this->generateInternalUri($controller, $options['path'], $options['query']);
$uri = $this->generateInternalUri($controller, $options['attributes'], $options['query']);

$alt = '';
if ($options['alt']) {
Expand All @@ -145,9 +145,9 @@ public function render($controller, array $options = array())
$subRequest = Request::create($controller, 'get', array(), $request->cookies->all(), array(), $request->server->all());
$subRequest->setSession($request->getSession());
} else {
$options['path']['_controller'] = $controller;
$options['path']['_format'] = $request->getRequestFormat();
$subRequest = $request->duplicate($options['query'], null, $options['path']);
$options['attributes']['_controller'] = $controller;
$options['attributes']['_format'] = $request->getRequestFormat();
$subRequest = $request->duplicate($options['query'], null, $options['attributes']);
}

try {
Expand All @@ -162,7 +162,7 @@ public function render($controller, array $options = array())
if ($options['alt']) {
$alt = $options['alt'];
unset($options['alt']);
$options['path'] = isset($alt[1]) ? $alt[1] : array();
$options['attributes'] = isset($alt[1]) ? $alt[1] : array();
$options['query'] = isset($alt[2]) ? $alt[2] : array();

return $this->render($alt[0], $options);
Expand All @@ -180,20 +180,20 @@ public function render($controller, array $options = array())
* This method uses the "_internal" route, which should be available.
*
* @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
* @param array $path An array of path parameters
* @param array $query An array of query parameters
* @param array $attributes An array of request attributes
* @param array $query An array of request query parameters
*
* @return string An internal URI
*/
public function generateInternalUri($controller, array $path = array(), array $query = array())
public function generateInternalUri($controller, array $attributes = array(), array $query = array())
{
if (0 === strpos($controller, '/')) {
return $controller;
}

$uri = $this->container->getRouterService()->generate('_internal', array(
'controller' => $controller,
'path' => $path ? http_build_query($path) : 'none',
'path' => $attributes ? http_build_query($attributes) : 'none',
'_format' => $this->container->getRequestService()->getRequestFormat(),
), true);

Expand Down
Expand Up @@ -51,16 +51,14 @@ public function output($controller, array $options = array())
* Returns the Response content for a given controller or URI.
*
* @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI
* @param array $attributes An array of request attributes
* @param array $options An array of options
*
* @see Symfony\Bundle\FrameworkBundle\Controller\ControllerResolver::render()
*/
public function render($controller, array $options = array())
public function render($controller, array $attributes = array(), array $options = array())
{
if (isset($options['path']))
{
$options['path'] = Escaper::unescape($options['path']);
}
$options['attributes'] = Escaper::unescape($attributes);

if (isset($options['query']))
{
Expand Down
4 changes: 2 additions & 2 deletions src/Symfony/Bundle/TwigBundle/Extension/Helpers.php
Expand Up @@ -46,8 +46,8 @@ public function getTokenParsers()
// {% route 'blog_post' with ['id': post.id] %}
new HelperTokenParser('route', '<route> [with <arguments:array>]', 'router', 'generate'),

// {% render 'BlogBundle:Post:list' with ['path': ['limit': 2], 'alt': 'BlogBundle:Post:error'] %}
new HelperTokenParser('render', '<template> [with <arguments:array>]', 'actions', 'render'),
// {% render 'BlogBundle:Post:list' with ['limit': 2], ['alt': 'BlogBundle:Post:error'] %}
new HelperTokenParser('render', '<template> [with <attributes:array>, [<options:array>]]', 'actions', 'render'),

// {% flash 'notice' %}
new HelperTokenParser('flash', '<name>', 'session', 'flash'),
Expand Down

0 comments on commit 994a6c3

Please sign in to comment.