From 39339121d6732cfd562958c352b18fccdb131eb3 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Tue, 19 Feb 2013 08:24:52 +0100 Subject: [PATCH] fixed HInclude renderer (closes #7113) --- ...ContainerAwareHIncludeFragmentRenderer.php | 4 ++- ...ainerAwareHIncludeFragmentRendererTest.php | 30 +++++++++++++++++++ .../Fragment/HIncludeFragmentRenderer.php | 10 +++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 src/Symfony/Bundle/FrameworkBundle/Tests/Fragments/ContainerAwareHIncludeFragmentRendererTest.php diff --git a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php index da273cd7a7..82c6a0b2b7 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php +++ b/src/Symfony/Bundle/FrameworkBundle/Fragment/ContainerAwareHIncludeFragmentRenderer.php @@ -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')); } 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 0000000000..546d48bc0b --- /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 1f6c2634bf..8b5610b31d 100644 --- a/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php +++ b/src/Symfony/Component/HttpKernel/Fragment/HIncludeFragmentRenderer.php @@ -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} *