From 3fe83cd7264bbc6a1688355bd2ff91e52d6c5711 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 18 May 2010 13:05:03 +0200 Subject: [PATCH] [WebBundle] finished the refactoring of the actions helper --- .../Controller/ControllerManager.php | 19 +++++++++ .../WebBundle/Helper/ActionsHelper.php | 39 +++++++------------ .../WebBundle/Resources/config/templating.xml | 2 +- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php b/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php index 957953a656..a78615e9ce 100644 --- a/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php +++ b/src/Symfony/Framework/WebBundle/Controller/ControllerManager.php @@ -5,6 +5,7 @@ namespace Symfony\Framework\WebBundle\Controller; use Symfony\Foundation\LoggerInterface; use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\HttpKernel\HttpKernelInterface; +use Symfony\Components\HttpKernel\Request; /* * This file is part of the Symfony framework. @@ -36,6 +37,13 @@ class ControllerManager /** * Renders a Controller and returns the Response content. * + * 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) + * * 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) + * * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $options An array of options * @@ -43,6 +51,17 @@ class ControllerManager */ public function render($controller, array $options = array()) { + $options = array_merge(array( + 'path' => array(), + 'query' => array(), + 'ignore_errors' => true, + 'alt' => array(), + ), $options); + + if (!is_array($options['alt'])) { + $options['alt'] = array($options['alt']); + } + $request = $this->container->getRequestService(); // controller or URI? diff --git a/src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php b/src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php index 95decdde6b..424e1feb52 100644 --- a/src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php +++ b/src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php @@ -3,10 +3,8 @@ namespace Symfony\Framework\WebBundle\Helper; use Symfony\Components\Templating\Helper\Helper; -use Symfony\Components\DependencyInjection\ContainerInterface; use Symfony\Components\OutputEscaper\Escaper; -use Symfony\Components\HttpKernel\HttpKernelInterface; -use Symfony\Components\HttpKernel\Request; +use Symfony\Framework\WebBundle\Controller\ControllerManager; /* * This file is part of the Symfony framework. @@ -26,16 +24,16 @@ use Symfony\Components\HttpKernel\Request; */ class ActionsHelper extends Helper { - protected $container; + protected $manager; /** * Constructor. * * @param Constructor $container A ContainerInterface instance */ - public function __construct(ContainerInterface $container) + public function __construct(ControllerManager $manager) { - $this->container = $container; + $this->manager = $manager; } /** @@ -54,33 +52,24 @@ class ActionsHelper extends Helper /** * Returns the Response content for a given controller or URI. * - * 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) - * * 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) - * * @param string $controller A controller name to execute (a string like BlogBundle:Post:index), or a relative URI * @param array $options An array of options + * + * @see Symfony\Framework\WebBundle\Controller\ControllerManager::render() */ public function render($controller, array $options = array()) { - $options = array_merge(array( - 'path' => array(), - 'query' => array(), - 'ignore_errors' => true, - 'alt' => array(), - ), $options); - - if (!is_array($options['alt'])) { - $options['alt'] = array($options['alt']); + if (isset($options['path'])) + { + $options['path'] = Escaper::unescape($options['path']); } - $options['path'] = Escaper::unescape($options['path']); - $options['query'] = Escaper::unescape($options['query']); + if (isset($options['query'])) + { + $options['query'] = Escaper::unescape($options['query']); + } - return $this->container->getControllerManagerService()->render($controller, $options); + return $this->manager->render($controller, $options); } /** diff --git a/src/Symfony/Framework/WebBundle/Resources/config/templating.xml b/src/Symfony/Framework/WebBundle/Resources/config/templating.xml index 41ab8211f9..eca249841f 100644 --- a/src/Symfony/Framework/WebBundle/Resources/config/templating.xml +++ b/src/Symfony/Framework/WebBundle/Resources/config/templating.xml @@ -81,7 +81,7 @@ - +