fd16993a37
This PR was squashed before being merged into the 3.4 branch (closes #22187).
Discussion
----------
[DependencyInjection] Support local binding
| Q | A
| ------------- | ---
| Branch? | master
| Bug fix? | no
| New feature? | yes <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks? | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass? | yes
| Fixed tickets | https://github.com/symfony/symfony/issues/22167, #23718
| License | MIT
| Doc PR |
> A great idea came out on Slack about local bindings.
> We could allow injecting services based on type hints on a per service/file basis:
> ```yml
> services:
> _defaults:
> bind:
> BarInterface: '@usual_bar'
>
> Foo:
> bind:
> BarInterface: '@alternative_bar'
> $quz: 'quzvalue'
> ```
>
> This way, `@usual_bar` will be injected in any parameter type hinted as `BarInterface` (in a constructor or a method signature), but only for this service/file.
> Note that bindings could be unused, giving a better solution than https://github.com/symfony/symfony/pull/22152 to https://github.com/symfony/symfony/pull/21711.
>
> As named parameters are usable in arguments, bindings could be usable in arguments too:
> ```yml
> services:
> Foo:
> arguments:
> BarInterface: '@bar'
> ```
~Named parameters aren't supported yet.~
Edit:
> Note that bindings could be unused
Current behavior is throwing an exception when a binding is not used at all, in no services of a file if it was inherited from `_defaults` or in no services created from a prototype.
It will pass if the bindings are all used in at least one service.
Commits
-------
|
||
---|---|---|
.. | ||
extension1 | ||
extension2 | ||
extensions | ||
class_from_id.xml | ||
legacy_invalid_alias_definition.xml | ||
namespaces.xml | ||
nested_service_without_id.xml | ||
nonvalid.xml | ||
services1.xml | ||
services2.xml | ||
services3.xml | ||
services4_bad_import.xml | ||
services4.xml | ||
services5.xml | ||
services6.xml | ||
services7.xml | ||
services8.xml | ||
services9.xml | ||
services10.xml | ||
services13.xml | ||
services14.xml | ||
services21.xml | ||
services22.xml | ||
services23.xml | ||
services24.xml | ||
services28.xml | ||
services_abstract.xml | ||
services_autoconfigure_with_parent.xml | ||
services_autoconfigure.xml | ||
services_bindings.xml | ||
services_defaults_with_parent.xml | ||
services_deprecated.xml | ||
services_instanceof_with_parent.xml | ||
services_instanceof.xml | ||
services_named_args.xml | ||
services_prototype.xml | ||
services_without_id.xml | ||
tag_with_empty_name.xml | ||
tag_without_name.xml | ||
with_key_outside_collection.xml | ||
withdoctype.xml | ||
xml_with_wrong_ext.php |