-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DependencyInjection] Make named arguments optional for prototypes #22152
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
Closed
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The reasoning for not applying this to instanceof conditionals and prototypes calls:
|
closing in favor of #22167 |
nicolas-grekas
added a commit
that referenced
this pull request
Aug 9, 2017
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 | #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 #22152 to #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
symfony-splitter
pushed a commit
to symfony/http-kernel
that referenced
this pull request
Aug 9, 2017
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 | symfony/symfony#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 symfony/symfony#22152 to symfony/symfony#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
symfony-splitter
pushed a commit
to symfony/dependency-injection
that referenced
this pull request
Aug 9, 2017
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 | symfony/symfony#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 symfony/symfony#22152 to symfony/symfony#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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes named arguments optional in prototypes: an argument can be declared but no used in every classes' constructor, note that this behavior is not applied to normal method calls.
To prevent typos, it must be used in at least one class, otherwise it throws an error.