-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Allow user to set the project dir #30651
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
Currently, the project directory is defined by the location of the composer.json file. That file is not required in production, which therefore breaks the method getProjectDir (who sends back null). This does not fix the behaviour, but allows the developer to pass the project dir as a parameter.
Thank you @tdutrion. |
@tdutrion Can you submit a PR for the recipe? |
This PR was merged into the 4.3-dev branch. Discussion ---------- Allow user to set the project dir | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes <!-- don't forget to update src/**/CHANGELOG.md files --> | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | <!-- symfony/symfony-docs#... required for new features --> Currently, the project directory is defined by the location of the composer.json file. That file is not required in production, which therefore [breaks the method getProjectDir](#23950) (who sends back null). The offered solution, while working, requires the developer to implement it, and uses inheritance override, while a more aesthetic solution could be used. This does not fix the behaviour, but allows the developer to pass the project dir as a parameter. While this solution does not include BC break or anything, it is important to notice that it includes **an optional parameter**. [Object instantiation in the framework bundle recipe](https://github.com/symfony/recipes/blob/master/symfony/framework-bundle/4.2/public/index.php#L23) could be updated as follow (in another PR): ```php $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); ``` ```php $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG'], dirname(__DIR__)); ``` Commits ------- c40017d Allow user to set the project dir
Done in symfony/recipes#555 |
I'm working on the changes needed for this in the docs ... and I wondered why do we need all this logic to calculate the project dir: symfony/src/Symfony/Component/HttpKernel/Kernel.php Lines 343 to 358 in 71c33c1
Do you consider making the |
While I'd love to have it mandatory, it seems to me that it would be a breaking change, so that would need to wait for a major version (let me know if I'm wrong there). |
Well, the drawback of relying on a constructor argument is that it means that each place instantiating the kernel has to know which value to pass it.
Requiring all these places to provide a configuration setting for which you need to pass the same project root looks like a bad experience to me. To me, a constructor argument here is actually a much worse DX than overriding the method. |
What we could do though is to throw an exception when the composer.json could not be found (asking to override the method or to keep the file) instead of returning a broken root dir, to improve DX. |
This is nice ... because it solves the problem without forcing the user to look for or read any docs. Just read the great exception message, make the changes, and you're done! |
Reading the discussion here, I'm wondering if you should revert this change. |
Makes sense. Let's revert. |
Don't forget symfony/recipes#555 if you revert |
One solution (the one I use in my projects) is instead to override the |
While this solution work, it's not as decent from a software engineering point of view, as it's again hiding the setting somewhere rather than forcing the developer who calls it to think where it's root his. Works for most symfony standard setup though, could be tricky if people do change the setup without understanding fully how things work. |
Well it feels more logical to me to put it in the
It's true if you define it in the |
reverted |
Currently, the project directory is defined by the location of the composer.json file.
That file is not required in production, which therefore breaks the method getProjectDir (who sends back null).
The offered solution, while working, requires the developer to implement it, and uses inheritance override, while a more aesthetic solution could be used.
This does not fix the behaviour, but allows the developer to pass the project dir as a parameter.
While this solution does not include BC break or anything, it is important to notice that it includes
an optional parameter.
Object instantiation in the framework bundle recipe could be updated as follow (in another PR):