[HttpKernel] made the strategy a regular parameter in HttpContentRenderer::render()

This commit is contained in:
Fabien Potencier 2013-01-06 09:31:07 +01:00
parent adc067e938
commit 1240690cac
4 changed files with 23 additions and 13 deletions

View File

@ -54,14 +54,15 @@ class HttpKernelExtension extends \Twig_Extension
*/
public function render($uri, $options = array())
{
return $this->renderer->render($uri, $options);
$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
unset($options['strategy']);
return $this->renderer->render($uri, $strategy, $options);
}
public function renderStrategy($strategy, $uri, $options = array())
{
$options['strategy'] = $strategy;
return $this->renderer->render($uri, $options);
return $this->renderer->render($uri, $strategy, $options);
}
public function controller($controller, $attributes = array(), $query = array())

View File

@ -101,6 +101,9 @@ class HttpKernel extends BaseHttpKernel
{
trigger_error('render() is deprecated since version 2.2 and will be removed in 2.3. Use Symfony\Component\HttpKernel\HttpContentRenderer::render() instead.', E_USER_DEPRECATED);
$this->container->get('http_content_renderer')->render($uri, $options);
$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
unset($options['strategy']);
$this->container->get('http_content_renderer')->render($uri, $strategy, $options);
}
}

View File

@ -46,7 +46,10 @@ class ActionsHelper extends Helper
*/
public function render($uri, array $options = array())
{
return $this->renderer->render($uri, $options);
$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
unset($options['strategy']);
return $this->renderer->render($uri, $strategy, $options);
}
public function controller($controller, $attributes = array(), $query = array())

View File

@ -81,23 +81,26 @@ class HttpContentRenderer implements EventSubscriberInterface
* When the Response is a StreamedResponse, the content is streamed immediately
* instead of being returned.
*
* * ignore_errors: true to return an empty string in case of an error
* * strategy: the strategy to use for rendering
* Available options:
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param array $options An array of options
* * ignore_errors: true to return an empty string in case of an error
*
* @param string|ControllerReference $uri A URI as a string or a ControllerReference instance
* @param string $strategy The strategy to use for the rendering
* @param array $options An array of options
*
* @return string|null The Response content or null when the Response is streamed
*/
public function render($uri, array $options = array())
public function render($uri, $strategy = 'default', array $options = array())
{
if (!isset($options['ignore_errors'])) {
$options['ignore_errors'] = !$this->debug;
}
$options = $this->fixOptions($options);
$strategy = isset($options['strategy']) ? $options['strategy'] : 'default';
if (isset($options['strategy'])) {
$strategy = $options['strategy'];
}
if (!isset($this->strategies[$strategy])) {
throw new \InvalidArgumentException(sprintf('The "%s" rendering strategy does not exist.', $strategy));