From 10947739995b315ab17c7db670ff0089a747f7ac Mon Sep 17 00:00:00 2001 From: Arthur de Moulins Date: Fri, 2 Dec 2016 16:57:47 +0100 Subject: [PATCH] inject project root path into twig filesystem loader --- .../DependencyInjection/Compiler/ExtensionPass.php | 6 +++++- .../Bundle/TwigBundle/Loader/FilesystemLoader.php | 9 +++++---- src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml | 5 +++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php index 603cbe8e22ef..dbad1b653c1d 100644 --- a/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php +++ b/src/Symfony/Bundle/TwigBundle/DependencyInjection/Compiler/ExtensionPass.php @@ -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()); diff --git a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php index 53fe300e29a6..0a9ac7a3ca19 100644 --- a/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php +++ b/src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php @@ -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; diff --git a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml index c82cbafbeb95..06af08d15ba7 100644 --- a/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml +++ b/src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml @@ -46,12 +46,13 @@ - + + @@ -87,7 +88,7 @@ - + %kernel.root_dir% %kernel.charset%