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
Fixes twig bundle project root dir discovery #22570
Conversation
$twigLoader = $container->getDefinition('twig.loader.native_filesystem'); | ||
if ($container->has('templating')) { | ||
$loader = $container->getDefinition('twig.loader.filesystem'); | ||
$loader->setMethodCalls(array_merge($twigLoader->getMethodCalls(), $loader->getMethodCalls())); | ||
$loader->replaceArgument(2, $composerRootDir); | ||
$loader->replaceArgument(2, $projectDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even better: use %kernel.project_dir%
directly in the service definition, and remove the handling of this argument from the compiler pass
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it now, you're right it should work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@stof did your changes.
$twigLoader = $container->getDefinition('twig.loader.native_filesystem'); | ||
if ($container->has('templating')) { | ||
$loader = $container->getDefinition('twig.loader.filesystem'); | ||
$loader->setMethodCalls(array_merge($twigLoader->getMethodCalls(), $loader->getMethodCalls())); | ||
$loader->replaceArgument(2, $composerRootDir); | ||
$loader->replaceArgument(2, $projectDir); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, got it now, you're right it should work.
Hum. I do need to fix tests. I obviously ran the wrong tests the first time. |
@stof how would you fix it for 3.2 and 3.0 since that the The question is not innocent, we do really experience this bug on production apps, and it needs fixing in current stable, I'm not fond in backporting a variable in stable, but it would help us fixing our env by just setting it. |
Only PHP 7.1 fails, but for a very deep unknown reason. |
Test OK locally. |
You need to bump the http-kernel dep in the twig bundle; This parameter exists as of 3.3
Maybe keep the current implementation, and consider it "improved" as of 3.3 |
The current implementation in 3.0 -> 3.2 is subject to the original bug I experienced: when the project root dir is under open_basedir restriction, TwigBundle skips the folder because it can't read the composer.json file, then the loop goes until it reaches the filesystem root and uses that instead. It needs fixing. |
@ro0NL in your opinion, should I get the getComposerDir() function back into the master and just conditionally use the kernel.project_root if exists ? |
In master
Thing is we cant backport a new feature (the project_dir param).. so we need a different approach on lower branches... ie. the current one. |
Doesn't the same situation occur with |
True.. but you can override the param way more easily :) and if overriden, we need to use that variant as well :) |
sure :) |
Using the project dir is the right approach for 3.3+. So to fix the build for deps=low, you just need to bump the min required version in TwigBundle |
Ok, I bumped the version, now the real tricky question arise: how do I fix it for 3.0 -> 3.2 versions knowing I have real sites in real productions buggy because of this ? |
you need to bump to 3.3 ;-) the param does not exists in 3.2.2. Maybe for lower branches we should start checking for |
Oh sorry, just stupidly ran the test locally and pushed... |
w00t, sorry for the noise, it should be OK now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Thank you @pounard. |
This PR was squashed before being merged into the 3.3-dev branch (closes #22570). Discussion ---------- Fixes twig bundle project root dir discovery | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22149 | License | MIT | Doc PR | none <!-- - Bug fixes must be submitted against the lowest branch where they apply (lowest branches are regularly merged to upper ones so they get the fixes too). - Features and deprecations must be submitted against the master branch. - Please fill in this template according to the PR you're about to submit. - Replace this comment by a description of what your PR is solving. --> TwigBundle ExtensionPass uses a directory lookup algorithm to find the composer.json file. When working under open_basedir restrictions, if the project root folder is not allowed PHP runtime to read, the composer.json will never be found, throwing PHP notices along the way and ending up using the filesystem root instead. Since that 3.3 introduced the kernel getProjectRoot() method and kernel.project_dir variable, the TwigBundle can now leverage it, in order to get more consistent, and allow site builders to override the getProjectRoot() kernel method, hence bypass the open_basedir restrictions in reliable and safe way. Commits ------- 3cb2e5b Fixes twig bundle project root dir discovery
TwigBundle ExtensionPass uses a directory lookup algorithm to find the composer.json file. When working under open_basedir restrictions, if the project root folder is not allowed PHP runtime to read, the composer.json will never be found, throwing PHP notices along the way and ending up using the filesystem root instead.
Since that 3.3 introduced the kernel getProjectRoot() method and kernel.project_dir variable, the TwigBundle can now leverage it, in order to get more consistent, and allow site builders to override the getProjectRoot() kernel method, hence bypass the open_basedir restrictions in reliable and safe way.