diff --git a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php index da273cd7a786..82c6a0b2b7f3 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php @@ -40,7 +40,9 @@ public function __construct(ContainerInterface $container, UriSigner $signer = n */ 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')); } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Fragments/ContainerAwareHIncludeFragmentRendererTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragments/ContainerAwareHIncludeFragmentRendererTest.php new file mode 100644 index 000000000000..546d48bc0b84 --- /dev/null +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Fragments/ContainerAwareHIncludeFragmentRendererTest.php @@ -0,0 +1,30 @@ + + * + * 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('/')); + } +} diff --git a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php index 1f6c2634bf03..8b5610b31dee 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -56,6 +56,16 @@ public function setTemplating($templating) $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} *