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

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

Merged
merged 1 commit into from Dec 5, 2016

Conversation

Projects
None yet
6 participants
@4rthem
Contributor

4rthem commented Dec 2, 2016

  • [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 -

@4rthem 4rthem changed the title from inject project root path into twig filesystem loader to [TwigBundle] Inject project root path into twig filesystem loader Dec 2, 2016

{
parent::__construct(array());
parent::__construct(array(), realpath($rootPath));

This comment has been minimized.

@stof

stof Dec 2, 2016

Member

it should pass the rootPath without altering it. Thus, not all filesystems support realpath

@@ -52,6 +52,7 @@
<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>%kernel.root_dir%/..</argument>

This comment has been minimized.

@stof

stof Dec 2, 2016

Member

this should use the same value than for twig.loader.native_filesystem instead, which is configured in a compiler pass and deals with passing the path without using /.. (which would not play well with systems not supporting realpath)

This comment has been minimized.

@4rthem

4rthem Dec 2, 2016

Contributor

Sorry, I didn't take time to look at the new code in 3.2...

@@ -52,6 +52,7 @@
<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></argument> <!-- project's root dir -->

This comment has been minimized.

@ogizanagi

ogizanagi Dec 2, 2016

Member
- <argument></argument> <!-- project's root dir -->
+ <argument /> <!-- project's root dir -->

(for consistency)

EDIT: Just saw the twig.loader.native_filesystem definition didn't use this notation, but it's the most common one in symfony core.

@@ -64,6 +64,11 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}
if ($container->has('twig.loader.filesystem')) {

This comment has been minimized.

@ogizanagi

ogizanagi Dec 2, 2016

Member

I think this check is not useful. The service should exist and is loaded by the bundle extension.

We do not have such check here for instance.

@@ -64,6 +64,9 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.extension.debug')->addTag('twig.extension');
}
$loader = $container->getDefinition('twig.loader.filesystem');
$loader->replaceArgument(2, $this->getComposerRootDir($container->getParameter('kernel.root_dir')));

This comment has been minimized.

@Tobion

Tobion Dec 2, 2016

Member

getComposerRootDir should only be executed once and reused below

This comment has been minimized.

@4rthem

4rthem Dec 5, 2016

Contributor

Done.

*/
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser)
public function __construct(FileLocatorInterface $locator, TemplateNameParserInterface $parser, $rootPath = '')

This comment has been minimized.

@Tobion

Tobion Dec 2, 2016

Member

the default value for $rootPath is null in the parent class and the child should use the same approach.

This comment has been minimized.

@4rthem

4rthem Dec 5, 2016

Contributor

My aim was to avoid the getcwd because this is the issue in a Symfony context (twigphp/Twig#2281).
But OK, the job is done by the compiler pass.

* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param FileLocatorInterface $locator A FileLocatorInterface instance
* @param TemplateNameParserInterface $parser A TemplateNameParserInterface instance
* @param string $rootPath The project's root dir

This comment has been minimized.

This comment has been minimized.

@4rthem

4rthem Dec 5, 2016

Contributor

Done.

@fabpot

This comment has been minimized.

Member

fabpot commented Dec 5, 2016

Thank you @4rthem.

@fabpot fabpot merged commit 1094773 into symfony:3.2 Dec 5, 2016

3 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
fabbot.io Your code looks good.
Details

fabpot added a commit that referenced this pull request Dec 5, 2016

bug #20727 [TwigBundle] Inject project root path into twig filesystem…
… 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

@4rthem 4rthem deleted the 4rthem:twig-project-root-path branch Dec 5, 2016

@fabpot fabpot referenced this pull request Dec 13, 2016

Merged

Release v3.2.1 #20897

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment