Skip to content

Commit

Permalink
bug #20727 [TwigBundle] Inject project root path into twig filesystem…
Browse files Browse the repository at this point in the history
… loader (4rthem)

This PR was merged into the 3.2 branch.

Discussion
----------

[TwigBundle] Inject project root path into twig filesystem loader

 * [TwigBundle] added project root path to filesystem loader

| Q             | A
| ------------- | ---
| Branch?       | 3.2
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #20726
| License       | MIT
| Doc PR        | -

Commits
-------

1094773 inject project root path into twig filesystem loader
  • Loading branch information
fabpot committed Dec 5, 2016
2 parents 8c22de4 + 1094773 commit 2d42689
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
Expand Up @@ -64,9 +64,13 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}

$composerRootDir = $this->getComposerRootDir($container->getParameter('kernel.root_dir'));
$loader = $container->getDefinition('twig.loader.filesystem');
$loader->replaceArgument(2, $composerRootDir);

if (!$container->has('templating')) {
$loader = $container->getDefinition('twig.loader.native_filesystem');
$loader->replaceArgument(1, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));
$loader->replaceArgument(1, $composerRootDir);
$loader->addTag('twig.loader');
$loader->setMethodCalls($container->getDefinition('twig.loader.filesystem')->getMethodCalls());

Expand Down
9 changes: 5 additions & 4 deletions src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php
Expand Up @@ -29,12 +29,13 @@ class FilesystemLoader extends \Twig_Loader_Filesystem
/**
* Constructor.
*
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param string|null $rootPath The root path common to all relative paths (null for getcwd())
*/
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, $rootPath = null)
{
parent::__construct(array());
parent::__construct(array(), $rootPath);

$this->locator = $locator;
$this->parser = $parser;
Expand Down
5 changes: 3 additions & 2 deletions src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Expand Up @@ -46,12 +46,13 @@

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

<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 -->
<tag name="twig.loader"/>
</service>

Expand Down Expand Up @@ -87,7 +88,7 @@

<service id="twig.extension.code" class="Symfony\Bridge\Twig\Extension\CodeExtension" public="false">
<tag name="twig.extension" />
<argument type="service" id="debug.file_link_formatter"></argument>
<argument type="service" id="debug.file_link_formatter" />
<argument>%kernel.root_dir%</argument>
<argument>%kernel.charset%</argument>
</service>
Expand Down

0 comments on commit 2d42689

Please sign in to comment.