Fixes twig bundle project root dir discovery

This commit is contained in:
Pierre Rineau 2017-04-28 12:25:29 +02:00 committed by Fabien Potencier
parent 9d9f628d92
commit 3cb2e5b7dd
5 changed files with 4 additions and 20 deletions

View File

@ -80,16 +80,13 @@ class ExtensionPass implements CompilerPassInterface
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}
$composerRootDir = $this->getComposerRootDir($container->getParameter('kernel.root_dir'));
$twigLoader = $container->getDefinition('twig.loader.native_filesystem');
if ($container->has('templating')) {
$loader = $container->getDefinition('twig.loader.filesystem');
$loader->setMethodCalls(array_merge($twigLoader->getMethodCalls(), $loader->getMethodCalls()));
$loader->replaceArgument(2, $composerRootDir);
$twigLoader->clearTag('twig.loader');
} else {
$twigLoader->replaceArgument(1, $composerRootDir);
$container->setAlias('twig.loader.filesystem', new Alias('twig.loader.native_filesystem', false));
}
@ -109,18 +106,4 @@ class ExtensionPass implements CompilerPassInterface
$container->getDefinition('twig.extension.expression')->addTag('twig.extension');
}
}
private function getComposerRootDir($rootDir)
{
$dir = $rootDir;
while (!file_exists($dir.'/composer.json')) {
if ($dir === dirname($dir)) {
return $rootDir;
}
$dir = dirname($dir);
}
return $dir;
}
}

View File

@ -7,7 +7,7 @@
<service id="twig.loader.filesystem" class="Symfony\Bundle\TwigBundle\Loader\FilesystemLoader" public="false">
<argument type="service" id="templating.locator" />
<argument type="service" id="templating.name_parser" />
<argument /> <!-- project's root dir -->
<argument>%kernel.project_dir%</argument>
<tag name="twig.loader"/>
</service>

View File

@ -48,7 +48,7 @@
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
<argument type="collection" /> <!-- paths -->
<argument /> <!-- project's root dir -->
<argument>%kernel.project_dir%</argument>
<tag name="twig.loader"/>
</service>

View File

@ -256,6 +256,7 @@ class TwigExtensionTest extends TestCase
$container = new ContainerBuilder(new ParameterBag(array(
'kernel.cache_dir' => __DIR__,
'kernel.root_dir' => __DIR__.'/Fixtures',
'kernel.project_dir' => __DIR__,
'kernel.charset' => 'UTF-8',
'kernel.debug' => false,
'kernel.bundles' => array(

View File

@ -20,7 +20,7 @@
"symfony/config": "~3.2",
"symfony/twig-bridge": "^3.2.1",
"symfony/http-foundation": "~2.8|~3.0",
"symfony/http-kernel": "~2.8.16|~3.1.9|^3.2.2",
"symfony/http-kernel": "^3.3",
"twig/twig": "^1.32|^2.2"
},
"require-dev": {