Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[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

Conversation

4rthem
Copy link
Contributor

@4rthem 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 inject project root path into twig filesystem loader [TwigBundle] Inject project root path into twig filesystem loader Dec 2, 2016
{
parent::__construct(array());
parent::__construct(array(), realpath($rootPath));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@4rthem 4rthem force-pushed the twig-project-root-path branch from f3eea6b to b999708 Compare December 2, 2016 16:57
@@ -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 -->
Copy link
Contributor

@ogizanagi ogizanagi Dec 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

- <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')) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@4rthem 4rthem force-pushed the twig-project-root-path branch from b999708 to 7037a44 Compare December 2, 2016 17:35
@@ -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')));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getComposerRootDir should only be executed once and reused below

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@4rthem 4rthem force-pushed the twig-project-root-path branch from 7037a44 to 1094773 Compare December 5, 2016 09:46
@fabpot
Copy link
Member

fabpot commented Dec 5, 2016

Thank you @4rthem.

@fabpot fabpot merged commit 1094773 into symfony:3.2 Dec 5, 2016
fabpot added a commit that referenced this pull request Dec 5, 2016
… 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 twig-project-root-path branch December 5, 2016 13:19
@fabpot fabpot mentioned this pull request Dec 13, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.