-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix PSR4 in composer.json, add dump() #490
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
e1a9581
to
3adc0b9
Compare
👍 |
"classmap": [ "app/AppKernel.php", "app/AppCache.php" ] | ||
}, | ||
"autoload-dev": { | ||
"psr-4": { "Tests\\": "tests/" } | ||
"psr-4": { "Tests\\": "tests/" }, | ||
"files": [ "vendor/symfony/symfony/src/Symfony/Component/VarDumper/Resources/functions/dump.php" ] |
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.
why is this needed? isn't it supposed to already be included from the VarDumper composer.json
?
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 is more as to ask for clarifications. I seem to be unable to use the dump
function when the app is not bootstrapped sometimes so I took the habit to add a shortcut to make a FQCN call to avoid that problem, but this still looks weird as I would expect to be able to use dump
at anytime.
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.
When symfony/symfony is required, the dump function is not autoloaded. It is only when symfony/var-dumper directly is.
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.
Isn't the dump
function loaded when Debug::enable()
is called?
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.
@Pierstoval no, it is loaded when the DebugBundle is booted. but when running tests, it is common for it not to be booted, making it painful. This is why we added it as a dev autoloading here for convenience.
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.
Then symfony/symfony-standard#1025 should also be merged, shouldn't it? :)
Nice! I think this is important, so I've tweeted about it https://twitter.com/symfony_en/status/836232295329722370 |
This PR was merged into the master branch. Discussion ---------- Fix PSR4 in composer.json, add dump() Empty psr-4 prefixes can force the autoloader to scan the `src/` directory for all namespaces. The best practice is to always have make the prefix explicit. `composer update` also, doing: ``` - Updating twig/twig (v1.31.0 => v1.32.0) Loading from cache - Updating sensiolabs/security-checker (v4.0.0 => v4.0.1) Loading from cache - Updating phpunit/php-timer (1.0.8 => 1.0.9) Loading from cache - Updating phpunit/php-token-stream (1.4.9 => 1.4.11) Loading from cache ``` Commits ------- 3adc0b9 Fix PSR4 in composer.json, add dump()
@@ -4,11 +4,15 @@ | |||
"type": "project", | |||
"description": "Symfony Demo Application", | |||
"autoload": { | |||
"psr-4": { "": "src/" }, | |||
"psr-4": { |
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.
whilst this may boost performance, it may be harder for new users don't you think?
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.
But only if you create a ton of bundles in your app ... which by the way is now considered a bad practice in most of the cases!
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.
Well to be honest I don't even see why you need any bundle here in the first place, but it's not limited to bundles. It highly depends on how you manage your src
bundle. I would personally promote more something like having a App
namespace for the whole src
.
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.
@theofidry the symfony-demo project has a AppBundle namespace for its source, because this is what the Symfony best practices are telling (and the demo is also about showing these best practices).
The extra CodeExplorerBundle is more a project-specific vendor bundle actually (we haven't shared it as a real vendor bundle, because this feature simply does not make sense outside the demo project).
and enw users won't find it harder, as they won't need to change the autoload config of symfony-demo.
First of all, nice catch ! I think the idealist way would be that composer has a way to load this from an external file, which would be generated by symfony on cache warm up for prod env. What do you think ? I would really appreciate your opinions on this. Thanks by advance. And once more, great job for digging this. |
@babaorum my humble opinion: we can wonder how the world could be better with more things being done out of the box, but that's really hard, many tried already with some success (composer is great!), and that's always improving. If you think you have some ideas that could make all of this even better, PRs are welcomed on both Composer and Symfony. For this very PR, it's unrelated. Just my 2cts :) |
The issue only exists in the developper environment because when you push your code in production, you should use |
@juliendufresne |
This PR was merged into the 2.7 branch. Discussion ---------- Improve PSR-4 autoloading by default TL;DR: (updated Marth 3rd) Before, I proposed to use any optimization by default in `composer.json` (complementary to PSR-4 autoload for the AppBundle). I took note of the different arguments and removed loaders optimization because it is not suitable for dev environments, but kept AppBundle PSR-4 explicit load because it encourages PSR-4 best practices of autoload. --- As seen on symfony/demo#490 (and it's certainly a well-known issue for developers using PHP Inspections EA Extended plugin for PHPStorm), having empty namespaces in `psr-4` rules has an impact on performances. Using this by default on the Standard Edition may encourage developers to add PSR-4 rules if they create new namespaces (for example if they want to create bundleless apps or other bundles, or components inside the same app, etc.). What do you think about putting this in the SE? Also, for best autoloading performances, it is recommended to use `classmap-authoritative` options (which adds `optimize-autoloader` implicitly). I added it in the `composer.json` but I'm not sure whether it's the best option to propose to Symfony newcomers (because `composer install` and `update` takes more time to execute). For this have a question: should we recommend `classmap-authoritative` or `optimize-autoloader` (or nothing ❔) by default ? Commits ------- 5f7ef8c Improve PSR-4 autoload by default
Empty psr-4 prefixes can force the autoloader to scan the
src/
directory for all namespaces. The best practice is to always make the prefix explicit.composer update
also, doing: