Skip to content

Commit

Permalink
[WebBundle] finished the refactoring of the actions helper
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed May 18, 2010
1 parent 3749c59 commit 3fe83cd
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
19 changes: 19 additions & 0 deletions src/Symfony/Framework/WebBundle/Controller/ControllerManager.php
Expand Up @@ -5,6 +5,7 @@
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.
Expand Down Expand Up @@ -36,13 +37,31 @@ public function __construct(ContainerInterface $container, LoggerInterface $logg
/**
* 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
*
* @return string The Response content
*/
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?
Expand Down
39 changes: 14 additions & 25 deletions src/Symfony/Framework/WebBundle/Helper/ActionsHelper.php
Expand Up @@ -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.
Expand All @@ -26,16 +24,16 @@
*/
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;
}

/**
Expand All @@ -54,33 +52,24 @@ public function output($controller, array $options = array())
/**
* 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);
}

/**
Expand Down
Expand Up @@ -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" />
Expand Down

0 comments on commit 3fe83cd

Please sign in to comment.