[WebBundle] finished the refactoring of the actions helper

This commit is contained in:
Fabien Potencier 2010-05-18 13:05:03 +02:00
parent 3749c59041
commit 3fe83cd726
3 changed files with 34 additions and 26 deletions

View File

@ -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?

View File

@ -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);
}
/**

View File

@ -81,7 +81,7 @@
<service id="templating.helper.actions" class="%templating.helper.actions.class%">
<annotation name="templating.helper" alias="actions" />
<argument type="service" id="service_container" />
<argument type="service" id="controller_manager" />
</service>
<service id="templating.loader" alias="templating.loader.filesystem" />