8000 inject project root path into twig filesystem loader · Padam87/symfony@1094773 · GitHub
[go: up one dir, main page]

Skip to content

Commit 1094773

Browse files
committed
inject project root path into twig filesystem loader
1 parent 8c22de4 commit 1094773

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,13 @@ public function process(ContainerBuilder $container)
6464
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
6565
}
6666

67+
$composerRootDir = $this->getComposerRootDir($container->getParameter('kernel.root_dir'));
68+
$loader = $container->getDefinition('twig.loader.filesystem');
69+
$loader->replaceArgument(2, $composerRootDir);
70+
6771
if (!$container->has('templating')) {
6872
$loader = $container->getDefinition('twig.loader.native_filesystem');
69-
$loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));
73+
$loader->replaceArgument(1, $composerRootDir);
7074
$loader->addTag('twig.loader');
7175
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());
7276

src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,13 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
2929
/**
3030
* Constructor.
3131
*
32-
* @param FileLocatorInterface $locator A FileLocatorInterface instance
33-
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
32+
* @param FileLocatorInterface $locator A FileLocatorInterface instance
33+
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
34+
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
3435
*/
35-
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
36+
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, $rootPath = null)
3637
{
37-
parent::__construct(array());
38+
parent::__construct(array(), $rootPath);
3839

3940
$this->locator = $locator;
4041
$this->parser = $parser;

src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,13 @@
4646

4747
<service id="twig.loader.native_filesystem" class="Twig_Loader_Filesystem" public="false">
4848
<argument type="collection" /> <!-- paths -->
49-
<argument></argument> <!-- project's root dir -->
49+
<argument /> <!-- project's root dir -->
5050
</service>
5151

5252
<service id="twig.loader.filesystem" class="Symfony\Bundle\TwigBundle\Loader\FilesystemLoader" public="false">
5353
<argument type="service" id="templating.locator" />
5454
<argument type="service" id="templating.name_parser" />
55+
<argument /> <!-- project's root dir -->
5556
<tag name="twig.loader"/>
5657
</service>
5758

@@ -87,7 +88,7 @@
8788

8889
<service id="twig.extension.code" class="Symfony\Bridge\Twig\Extension\CodeExtension" public="false">
8990
<tag name="twig.extension" />
90-
<argument type="service" id="debug.file_link_formatter"></argument>
91+
<argument type="service" id="debug.file_link_formatter" />
9192
<argument>%kernel.root_dir%</argument>
9293
<argument>%kernel.charset%</argument>
9394
</service>

0 commit comments

Comments
 (0)
0