This repository has been archived on 2023-08-20. You can view files and clone it, but cannot push or open issues or pull requests.
symfony/src/Symfony/Component/DependencyInjection/Loader
Nicolas Grekas fd16993a37 feature #22187 [DependencyInjection] Support local binding (GuilhemN)
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
-------

81f2652 [DependencyInjection] Support local binding
2017-08-09 11:26:28 +02:00
..
schema/dic/services [DependencyInjection] Support local binding 2017-08-09 11:26:25 +02:00
ClosureLoader.php [DependencyInjection] fix phpDoc 2016-04-11 16:45:49 +02:00
DirectoryLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
FileLoader.php Allowing prototype/PSR4 service loading ability to exclude, because glob doesn't support this 2017-05-13 13:10:49 -04:00
IniFileLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
PhpFileLoader.php [Config][DI] Add ComposerResource to track runtime + vendors 2017-02-07 15:42:58 +01:00
XmlFileLoader.php feature #22187 [DependencyInjection] Support local binding (GuilhemN) 2017-08-09 11:26:28 +02:00
YamlFileLoader.php feature #22187 [DependencyInjection] Support local binding (GuilhemN) 2017-08-09 11:26:28 +02:00