From 2be8b6e2eac24f9f576c5591cc9e7bf49244a19f Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Mon, 12 Jan 2015 14:42:13 +0100 Subject: [PATCH] [TwigBundle] optimized the hinclude fragement renderer when only Twig is used --- .../DependencyInjection/Compiler/ExtensionPass.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index 953a9dd9dd..b325836281 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -13,6 +13,7 @@ namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\ContainerBuilder; +use Symfony\Component\DependencyInjection\Reference; /** * @author Jean-François Simon @@ -41,6 +42,17 @@ class ExtensionPass implements CompilerPassInterface if ($container->has('fragment.handler')) { $container->getDefinition('twig.extension.httpkernel')->addTag('twig.extension'); + + // inject Twig in the hinclude service if Twig is the only registered templating engine + if ( + !$container->hasParameter('templating.engines') + || array('twig') == $container->getParameter('templating.engines') + ) { + $container->getDefinition('fragment.renderer.hinclude') + ->addTag('kernel.fragment_renderer', array('alias' => 'hinclude')) + ->replaceArgument(0, new Reference('twig')) + ; + } } if ($container->has('request_stack')) {