8000 Fixes twig bundle project root dir discovery by pounard · Pull Request #22570 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Fixes twig bundle project root dir discovery #22570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,13 @@ public function process(ContainerBuilder $container)
$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));
}

Expand All @@ -109,18 +106,4 @@ public function process(ContainerBuilder $container)
$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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ private function createContainer()
$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(
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/TwigBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
0