Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[TwigBundle] Renderer::evaluate() should ensure the Request is both d…
…efined and non-empty

This addresses an oversight in my previous commit: 9553971
Author: Jeremy Mikola <jmikola@gmail.com>
Date:   Thu Jan 6 13:26:45 2011 -0500
  • Loading branch information
jmikola authored and fabpot committed Jan 7, 2011
1 parent 025f3b1 commit 0c50ca8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/Symfony/Bundle/TwigBundle/Renderer/Renderer.php
Expand Up @@ -37,9 +37,10 @@ public function __construct(\Twig_Environment $environment)
*/
public function evaluate(Storage $template, array $parameters = array())
{
if ($this->engine->getContainer()->has('request')) {
// cannot be set in the constructor as we need the current request
$request = $this->engine->getContainer()->get('request');
$container = $this->engine->getContainer();

// cannot be set in the constructor as we need the current request
if ($container->has('request') && ($request = $container->get('request'))) {
$this->environment->addGlobal('request', $request);
$this->environment->addGlobal('session', $request->getSession());
}
Expand Down
Expand Up @@ -42,7 +42,8 @@ public function testEvalutateWithoutAvailableRequest()
$environment = $this->getTwigEnvironment();
$renderer = new Renderer($environment);

$engine = new Engine(new Container(), $this->getMock('Symfony\Component\Templating\Loader\LoaderInterface'), array());
$container = new Container();
$engine = new Engine($container, $this->getMock('Symfony\Component\Templating\Loader\LoaderInterface'), array());

$storage = $this->getStorage();
$template = $this->getMock('\Twig_TemplateInterface');
Expand All @@ -52,6 +53,7 @@ public function testEvalutateWithoutAvailableRequest()
->with($storage)
->will($this->returnValue($template));

$container->set('request', null);
$renderer->setEngine($engine);
$renderer->evaluate($storage);

Expand Down

0 comments on commit 0c50ca8

Please sign in to comment.