-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[HttpKernel] Fix kernel.project_dir extensibility #22728
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
Conversation
9c1312e
to
8efecd1
Compare
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.
👍
This would be inconsistent with the |
yes - but we dont care :) if you want consistency use the method as extension hook for both. |
Yes it's inconsistent, but allows for better maintainability and user experience at the end. There is a lot |
Is it really required considering it's already computed once using |
@ogizanagi is right, but I think it's better to always call the method. If the constructor behavior changes a day, and given the method itself return the property if initialized, I think it's sane to use it rather than the prop. |
@ogizanagi you could add a method in your kernel that modifies the return value of |
That is exactly the point. Originally, we had a |
If this is to be merged, the method must not be called on the constructor, otherwise calling the method in |
Agree; not sure what's the lazy initialization is about. But it doesnt harm really :) |
I don't think so. The getter is the extension point. The private property is set at construction so that it is always available internally; and the method is called when needed. As pointed by @jvasseur, the kernel state can change after construction, always calling the method is just safe-guard, that's fine to me. |
Changing this value after initialization looks weird to me honestly, so I don't really get the point, but ¯\_(ツ)_/¯. |
Not only the value itself, but some other properties on which the custom |
@chalasr: What about removing the the assignation on this line in this PR too, as discussed (as it's already done in the |
$kernel->boot(); | ||
|
||
$r = new \ReflectionMethod($kernel, 'getKernelParameters'); | ||
$r->setAccessible(true); |
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.
You're cheating ;-)
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.
Besides due the constructor initialization this test also passes without your change :) so we actually need to test some weird edge case here. Perhaps return different values on consecutive calls?
The property must not be used internally (except for the getter method) if the getter is to be the extension point! So there's no point in initializing it. |
Tend to agree with that :) it also makes the test valid. |
@@ -604,7 +604,7 @@ protected function getKernelParameters() | |||
return array_merge( | |||
array( | |||
'kernel.root_dir' => realpath($this->rootDir) ?: $this->rootDir, | |||
'kernel.project_dir' => realpath($this->projectDir) ?: $this->projectDir, | |||
'kernel.project_dir' => realpath($this->getProjectDir()) ?: $this->getProjectDir(), |
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.
Should we use the getter variant for other params too, while at it?
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.
Yea I think, I'll do it separately for lower branches once this merged
f9c5705
to
234361e
Compare
constructor assignment removed, changed the test to better show what this prevents. |
ping @symfony/deciders |
👍 |
Thank you @chalasr. |
This PR was merged into the 3.3 branch. Discussion ---------- [HttpKernel] Fix kernel.project_dir extensibility | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #22727 | License | MIT | Doc PR | n/a Alternative to #22727 that makes use of the existing public api. Commits ------- 3230fc7 Fix kernel.project_dir extensibility
Alternative to #22727 that makes use of the existing public api.