inject project root path into twig filesystem loader

This commit is contained in:
Arthur de Moulins 2016-12-02 16:57:47 +01:00
parent 8c22de44cd
commit 1094773999
3 changed files with 13 additions and 7 deletions

View File

@ -64,9 +64,13 @@ class ExtensionPass implements CompilerPassInterface
$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());

View File

@ -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;

View File

@ -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>
@ -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>