-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Add a warning to imports order #12318
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
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.
Thanks for the very detailed PR description! Looks like a perfect caution to me.
@wouterj don't you think that this is a Symfony bug? In the docs we always explain that "_defaults apply to services created in this file". If you import some config file ... you should accept the services as they are created in the other files ... and your "_defaults" shouldn't apply to them, right? Am I missing something? |
@javiereguiluz that's exactly what's happening here. The |
Lastly defined services override previous one. That's the rule since 2.0, it applies here too. |
Now I see my mistake. I completely misunderstood. I think it makes sense because of the |
I'd suggest to remove the "FUD" part of the message and keep it strictly factual. |
In fact, I think the real problem is that this is an old article. At that time, Symfony forced you to write a 3,000-line config file for services, so splitting into multiple files may make sense. But that's no longer the case. The services file is short even for complex apps (when using autowiring/autoconfiguration) so you don't really need imports most of the times. |
96aa820
to
175b05a
Compare
This PR was submitted for the master branch but it was squashed and merged into the 4.3 branch instead (closes #12318). Discussion ---------- Add a warning to imports order After spending few hours narrowing this down, I've added a note in the documentation that potentially will save time for developper; Here's what happened to me: I got a service that didn't worked, it's because the `imports` actually imports the file *before*, so the service definition got overriden with no warning by the Glob rule (`App\:`) This behaviour is not mentionned on the documentation; ```yaml // services.yaml imports: - { resource: actions_services.yaml } services: # default configuration for services in *this* file _defaults: autowire: true autoconfigure: true App\: resource: '../src/*' exclude: - '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' ``` ```yaml // actions_services.yaml services: App\Actions\Company\CreateCompany: autowire: true autoconfigure: false parent: 'App\Handler\AbstractHandler' calls: - [setClient, ['@app\GraphQL\Client']] - [setEndpointUrlResolver, ['@app\Resolver\EndpointResolver']] - [setSuccessor, ['@app\Actions\User\CreateUser']] ``` <img width="549" alt="tbessoussa_MacBook-Pro-dex-Tristan____workspace_importer-function" src="https://user-images.githubusercontent.com/346010/64860934-eaf0cc80-d62e-11e9-94e9-a0da67d1b366.png"> **Note that the `Calls` section is missing** Working version: ```yaml // services.yaml services: # default configuration for services in *this* file _defaults: autowire: true autoconfigure: true App\: resource: '../src/*' exclude: - '../src/{DependencyInjection,Entity,Migrations,Tests,Kernel.php}' App\Actions\Company\CreateCompany: autowire: true autoconfigure: false parent: 'App\Handler\AbstractHandler' calls: - [setClient, ['@app\GraphQL\Client']] - [setEndpointUrlResolver, ['@app\Resolver\EndpointResolver']] - [setSuccessor, ['@app\Actions\User\CreateUser']] ``` <img width="712" alt="tbessoussa_MacBook-Pro-de-Tristan____workspace_importer-function" src="https://user-images.githubusercontent.com/346010/64860840-a9602180-d62e-11e9-9b3a-40e344f18e9f.png"> `Calls` is here, so the service is good to go. Commits ------- 175b05a Add a warning to imports order
Thanks Tristan! This is now merged. I reworded it a bit to remove the |
Thanks; Note that splitting services in external files are still required when you use |
If you ask me ... I'd remove |
After spending few hours narrowing this down, I've added a note in the documentation that potentially will save time for developper;
Here's what happened to me: I got a service that didn't worked, it's because the
imports
actually imports the file before, so the service definition got overriden with no warning by the Glob rule (App\:
)This behaviour is not mentionned on the documentation;
Note that the
Calls
section is missingWorking version:
Calls
is here, so the service is good to go.