-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
kernel.project_dir (getProjectDir()) silently returns incorrect path without composer.json #23950
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
Comments
Well, if you don't want it to depend on the presence of the composer.json, you can overwrite the method in your own kernel. |
I agree with @stof (btw, you're not the only one cleaning composer.json, and this solution was provided before and was OK.) |
I agree with @stof and @nicolas-grekas. Thus, closing here as there is an easy way to override the project dir config if needed. |
So why is the projectDir variable private then? Why do I have to re-declare it in my kernel? |
@mvrhov the |
rootDir variable is protected.. so I can set it once and next time just return the cached value. |
@mvrhov rootDir being protected is a legacy reason. We cannot make it private due to the change being a BC break. but the new property can be private without issue. |
Hi, I just hit the same problem on production and I wondered, now that ".env" is required by public/index.php, if it couldn't be added to the test in Kernel::getProjectDir() with "composer.json" ? https://github.com/symfony/symfony/blob/master/src/Symfony/Component/HttpKernel/Kernel.php#L347 while (!file_exists($dir.'/composer.json') && !file_exists($dir.'/.env')) {
/* … */
} |
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](symfony/symfony#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
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
Currently in symfony 3.3.x parameter kernel.project_dir silently returns kernel_dir if composer.json is not found at all. IMHO it shouldn't be related with composer.json as in prod environment, composer is typically not needed at all, so files could be discarded from build artifacts. So even an error or a warning would be better here compared to option that you can get 2 different paths depending on that you have or not have a 3rd party file.
even cache:clear fails with missing files errors, if project_dir is used without composer.json file
The text was updated successfully, but these errors were encountered: