Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[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

Merged
merged 1 commit into from
May 25, 2017

Conversation

chalasr
Copy link
Member

@chalasr chalasr commented May 17, 2017

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.

Copy link
Member

@xabbuh xabbuh left a comment

Choose a reason for hiding this comment

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

👍

@aschempp
Copy link
Contributor

This would be inconsistent with the rootDir imho?

@ro0NL
Copy link
Contributor

ro0NL commented May 17, 2017

yes - but we dont care :)

if you want consistency use the method as extension hook for both.

@chalasr
Copy link
Member Author

chalasr commented May 17, 2017

Yes it's inconsistent, but allows for better maintainability and user experience at the end. There is a lot protected members in the core codebase, but since a long time, we do not introduce new ones without a strong reason, and we even made some private afterwards (generally through "opportunity").
Also, getProjectDir() makes rootDir obsolete, we should remove it on the long run, no need for changing this now.

@ogizanagi
Copy link
Contributor

ogizanagi commented May 17, 2017

@chalasr
Copy link
Member Author

chalasr commented May 17, 2017

@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.

@jvasseur
Copy link
Contributor

@ogizanagi you could add a method in your kernel that modifies the return value of getProjectDir between the moment the object is created and the moment the container is compiled.

@aschempp
Copy link
Contributor

aschempp commented May 17, 2017

you could add a method in your kernel that modifies the return value of getProjectDir between the moment the object is created and the moment the container is compiled.

That is exactly the point. Originally, we had a setRootDir method to tell the Kernel where it's root dir is located. Because our kernel is distributed with a bundle but the root dir is still /app. Now that does no longer work with projectDir, as we cannot override it after __construct (even though getKernelParameters has not been called yet).

@aschempp
Copy link
Contributor

If this is to be merged, the method must not be called on the constructor, otherwise calling the method in getKernelParameters does not make much sense to me.

@ro0NL
Copy link
Contributor

ro0NL commented May 17, 2017

Agree; not sure what's the lazy initialization is about. But it doesnt harm really :)

@chalasr
Copy link
Member Author

chalasr commented May 17, 2017

otherwise calling the method in getKernelParameters does not make much sense to me.

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.

@ogizanagi
Copy link
Contributor

you could add a method in your kernel that modifies the return value of getProjectDir between the moment the object is created and the moment the container is compiled.

the kernel state can change after construction

Changing this value after initialization looks weird to me honestly, so I don't really get the point, but ¯\_(ツ)_/¯.

@chalasr
Copy link
Member Author

chalasr commented May 17, 2017

Not only the value itself, but some other properties on which the custom getProjectRootdir() could rely on... it's all about weird edge cases, but preventing them in the parent class doesn't harm, and since we can do it easily...

@ogizanagi
Copy link
Contributor

@chalasr: What about removing the the assignation on this line in this PR too, as discussed (as it's already done in the Kernel::getProjectDir() implementation) ?

$kernel->boot();

$r = new \ReflectionMethod($kernel, 'getKernelParameters');
$r->setAccessible(true);
Copy link
Contributor

Choose a reason for hiding this comment

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

You're cheating ;-)

Copy link
Contributor

@ro0NL ro0NL May 17, 2017

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?

@aschempp
Copy link
Contributor

The private property is set at construction so that it is always available internally; and the method is called when needed.

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.

@ro0NL
Copy link
Contributor

ro0NL commented May 17, 2017

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(),
Copy link
Contributor

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?

Copy link
Member Author

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

@chalasr chalasr force-pushed the get-proj-dir branch 3 times, most recently from f9c5705 to 234361e Compare May 18, 2017 08:55
@chalasr
Copy link
Member Author

chalasr commented May 18, 2017

constructor assignment removed, changed the test to better show what this prevents.

@chalasr chalasr changed the base branch from master to 3.3 May 18, 2017 09:29
@nicolas-grekas nicolas-grekas added this to the 3.3 milestone May 18, 2017
@xabbuh
Copy link
Member

xabbuh commented May 22, 2017

ping @symfony/deciders

@Tobion
Copy link
Contributor

Tobion commented May 22, 2017

👍

@fabpot
Copy link
Member

fabpot commented May 25, 2017

Thank you @chalasr.

@fabpot fabpot merged commit 3230fc7 into symfony:3.3 May 25, 2017
fabpot added a commit that referenced this pull request May 25, 2017
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
@chalasr chalasr deleted the get-proj-dir branch May 26, 2017 01:57
@fabpot fabpot mentioned this pull request May 29, 2017
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.