Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5d7f4e1

Browse files
committed
bug #20712 [TwigBundle] Fix twig loader registered twice (ogizanagi)
This PR was merged into the 2.7 branch. Discussion ---------- [TwigBundle] Fix twig loader registered twice | Q | A | ------------- | --- | Branch? | 2.7 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #20665 | License | MIT | Doc PR | N/A Generated code: ### Before ```php protected function getTwig_LoaderService() { $a = new \Twig_Loader_Filesystem(array(), $this->targetDirs[3]); $a->addPath(...); // ... $this->services['twig.loader'] = $instance = new \Twig_Loader_Chain(); $instance->addLoader($a); $instance->addLoader($a); return $instance; } ``` ### After ```php protected function getTwig_LoaderService() { $this->services['twig.loader'] = $instance = new \Twig_Loader_Filesystem(array(), $this->targetDirs[3]); $instance->addPath(...); // ... return $instance; } ``` ~~Another solution is to simply create a private alias. But I don't know if we should care or not about the case people may rely on the fact both services exist as definition, and not as an alias, in a compiler pass.~~ (Has been preferred over of using a child definition) For reference, this issue was introduced in #13354. Commits ------- 2c81819 [TwigBundle] Fix twig loader registered twice
2 parents c360a22 + 2c81819 commit 5d7f4e1

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\TwigBundle\DependencyInjection\Compiler;
1313

14+
use Symfony\Component\DependencyInjection\Alias;
1415
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
1516
use Symfony\Component\DependencyInjection\ContainerBuilder;
1617
use Symfony\Component\DependencyInjection\Reference;
@@ -73,7 +74,7 @@ public function process(ContainerBuilder $container)
7374
$loader->addTag('twig.loader');
7475
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
7576

76-
$container->setDefinition('twig.loader.filesystem', $loader);
77+
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
7778
}
7879

7980
if ($container->has('assets.packages')) {

0 commit comments

Comments
 (0)