symfony: Importing configuration from other yaml file to config/services.yaml doesn't work
| Q | A |
|---|---|
| Bug report? | yes |
| Feature request? | no |
| BC Break report? | no |
| RFC? | no |
| Symfony version | 4.0.4 |
Importing configuration from other yaml file to config/services.yaml doesn’t work well. I made simple reproducer codebase here. Maybe seeing commit logs helps you to understand about my reporting. Thanks.
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 18 (9 by maintainers)
Just put your .yaml file in the dir config/services, and add to src/Kernel.php, at the end of the configureContainer method:
$loader->load($confDir.'/services/*'.self::CONFIG_EXTS, 'glob');This feels a bit counter-intuitive behavior to me as we are used to expect more specific definitions to override more generic ones. While the roots of the issue are quite clear once you spent some time to grasp it then the vague suggestion in documentation and few issues on github (this included) suggest more explicit filtering in the global auto-wiring definition in
services.yamland this looks a bit tedious and error prone process.Is it possible to call it a documentation bug instead and opt in for documenting the following (or similar) approach (or rather a suggestion) in the dedicated doc page (How to Import Configuration Files/Resources):
Once you decide to split into multiple service definition files one just needs to extract the golbal auto-wiring definition as well and just beware to import it first. E.g.
and then
IMO even if only a soft suggestion it will immediately rise awareness of what is going on. Alternative example with filtering out services could also be provided for verbosity.
I could try to provide a PR for the docs if it looks like something less confusing and “nice to have”? CC @xabbuh
I noticed some weird Symfony behaviour during import. When services are defined in config/services.yaml file, they are loading properly, but when I configure them in config/services/services.yaml, they start to give error like
Cannot autowire service “App\Command***\XyzCommand”: argument “$env” of method “__construct()” is type-hinted “string”, you should configure its
value explicitly.
what about
bind:?it won’t work if you move the argument
$my_argumentto anthor separatedservicesfile (e.gservices/something.yaml) and rather it throws this weired exception:if each
servicesfile has its ownbind:section, does this lead to conflict/overrids ? how to counter this properly ?If you want this to work IMHO, is to remove the
_defaultsfrom the services.yaml and add it in the sample.yaml.This is what i’m doing.
I can’t tell if it’s really a bug or a missusage.
Status: Needs Review