Skip to content

[TwigBundle] Inject project root path into twig filesystem loader #20727

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

Merged
merged 1 commit into from
Dec 5, 2016
Merged
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy