fixed HInclude renderer (closes #7113)

This commit is contained in:
Fabien Potencier 2013-02-19 08:24:52 +01:00
parent ec885bf5f4
commit 39339121d6
3 changed files with 43 additions and 1 deletions

View File

@ -40,7 +40,9 @@ class ContainerAwareHIncludeFragmentRenderer extends HIncludeFragmentRenderer
*/
public function render($uri, Request $request, array $options = array())
{
if (!$this->templating) {
// setting the templating cannot be done in the constructor
// as it would lead to an infinite recursion in the service container
if (!$this->hasTemplating()) {
$this->setTemplating($this->container->get('templating'));
}

View File

@ -0,0 +1,30 @@
<?php
/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Symfony\Bundle\FrameworkBundle\Tests\Fragment;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;
use Symfony\Bundle\FrameworkBundle\Fragment\ContainerAwareHIncludeFragmentRenderer;
use Symfony\Component\HttpFoundation\Request;
class ContainerAwareHIncludeFragmentRendererTest extends TestCase
{
public function testRender()
{
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
$container->expects($this->once())
->method('get')
->will($this->returnValue($this->getMock('\Twig_Environment')))
;
$renderer = new ContainerAwareHIncludeFragmentRenderer($container);
$renderer->render('/', Request::create('/'));
}
}

View File

@ -56,6 +56,16 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
$this->templating = $templating;
}
/**
* Checks if a templating engine has been set.
*
* @return Boolean true if the templating engine has been set, false otherwise
*/
public function hasTemplating()
{
return null !== $this->templating;
}
/**
* {@inheritdoc}
*