-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[DI] Replace autowiring BC break by regular deprecation #22384
New issue 8000
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
Conversation
4a0abde
to
0ed087d
Compare
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.
Deprecating rather than breaking BC is always better
@nicolas-grekas: Big thumbs up for this change! BC promise and being open & flexible with changes are the most important reason for using Symfony in serious projects. |
Thank you @nicolas-grekas. |
…n (nicolas-grekas) This PR was merged into the 3.3-dev branch. Discussion ---------- [DI] Replace autowiring BC break by regular deprecation | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | yes | Tests pass? | yes | Fixed tickets | - | License | MIT | Doc PR | - It happens that doing so is really easy now. And as discussed in #22295, this should be more friendly to our users. Commits ------- 0ed087d [DI] Replace autowiring BC break by regular deprecation
@@ -291,6 +291,12 @@ private function getAutowiredReference(TypedReference $reference) | |||
return new TypedReference($this->types[$type], $type); | |||
} | |||
|
|||
if (isset($this->types[$type])) { | |||
@trigger_error(sprintf('Autowiring services based on the types they implement is deprecated since Symfony 3.3 and won\'t be supported in version 4.0. You should %s the "%s" service to "%s" instead.', isset($this->types[$this->types[$type]]) ? 'alias' : 'rename (or alias)', $this->types[$type], $type), E_USER_DEPRECATED); |
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.
If somebody typehints an implementation instead of an interface, this deprecation is misleading. They do not need to change the services but also only change the typhint.
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.
This should be the case in createTypeAlternatives, see "or type-hint against etc."
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.
Yes but that only happens if no autowired service can be found. If it works with a by-type deprecation, the alternatives are not suggested.
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.
e.g. if you typehint the serializer implementation instead of the interface
It happens that doing so is really easy now. And as discussed in #22295, this should be more friendly to our users.