Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.7k
[Autowiring] Add interface FQCN as a valid service name to avoid collisions#21132
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
GuilhemN commentedJan 2, 2017
Sounds hard to support without having a dedicated system in services:CollisionInterface:'@app.b'app.a:class:Aautowire:trueapp.b:class:Aapp.use_collision:class:UseCollisionautowire:true |
dunglas commentedJan 3, 2017
Shouldn't we deprecate the |
| privatefunctioncreateAutowiredDefinition(\ReflectionClass$typeHint,$id) | ||
| { | ||
| if (isset($this->ambiguousServiceTypes[$typeHint->name])) { | ||
| if (isset($this->ambiguousServiceTypes[$typeHintName =$typeHint->name])) { |
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.
Why is necessary to create the$typeHintName variable? It makes the code harder to read for no benefit over using the prop directly.
| { | ||
| $container =newContainerBuilder(); | ||
| $container->register('c1',__NAMESPACE__.'\CollisionA'); |
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.
You can useCollisionA::class for Symfony 3+. Same of lines below.
theofidry commentedJan 3, 2017
I'm for it, but should it be done here or another PR? Also should this be merged in master or an older branch? |
theofidry commentedJan 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@GuilhemN I'm not sure to understand your concern, all services are registered being process that way so the order does not matter. |
GuilhemN commentedJan 3, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@theofidry oops, I didn't realize it was a PR and I was thinking you'll try to implement it otherwise... 😐 LGTM 👍 I'm also for deprecating the |
| $matchingServices =implode(',',$this->ambiguousServiceTypes[$typeHint->name]); | ||
| thrownewRuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).',$typeHint->name,$id,$classOrInterface,$matchingServices),1); | ||
| thrownewRuntimeException(sprintf('Unable to autowire argument of type "%s" for the service "%s". Multiple services exist for this %s (%s).',$typeHint->name,$id,$classOrInterface,$matchingServices)); |
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.
needs to be reverted
theofidry commentedJan 6, 2017
@dunglas updated, but I'm still unsure on which branch we should merge this as if we want to deprecate |
nicolas-grekas commentedJan 6, 2017
the deprecation part is for master for sure |
theofidry commentedJan 6, 2017 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@nicolas-grekas I'm actually not sure if this should be considered a feature or a bug (hence my question of which branch to target). The PR doesn't need to be split, deprecating |
dunglas commentedJan 6, 2017
👍 |
| privatefunctioncreateAutowiredDefinition(\ReflectionClass$typeHint,$id) | ||
| { | ||
| if (isset($this->ambiguousServiceTypes[$typeHint->name])) { | ||
| if ($this->container->has($typeHint->name)) { |
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.
Can't this be movedhere to avoid building the map when not necessary?
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.
Good point, gonna try
nicolas-grekas commentedFeb 1, 2017
Closing, see ##21494. |
theofidry commentedFeb 1, 2017
Thanks :) |
As of now, if you have:
It would fail, because you have
app.aandapp.bwhich are both implementingCollisionInterface. However as you can see, in this scenario this is a bit stupid, as if you bother doingCollisionInterface: '@app.b', this is equivalent to (or rather should be IMO) have:You might wonder what's the diff and why bother yourself with that, the diff IMO is the location of your service definitions. For example I may try to follow a more DDD oriented architecture, e.g. the hexagonal architecture, where I have:
and try to have something like:
I am not sure if this can be caused any BC and if this should be considered as a feature or a bugfix.
/cc@dunglas