Enable autowiring support for symfony 3.3+ #142
Merged
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.
What's in this PR?
This configure the
httplug.client
as being the right choice for autowiring in Symfony 3.3+ when being asked to autowire aHttp\Client\HttpClient
typehint.This also adds autowiring for all the message factory interfaces, using the main aliases as target.
Why?
Autowiring is one of the nice features of Symfony 3.3+ (working autowiring actually. We already have autowiring since 2.8 but it was not working well). So it is great to support it out of the box, especially when it has no impact for people using older versions or not using autowiring (the private alias just gets removed during the container optimizations anyway).
Autowiring support cannot be enabled for Symfony 2.8 to 3.1 for people using multiple clients because resolving ambiguities cannot be done by targeting an alias in these versions. Projects using a single client may experience a working autowiring in this case. But enabling the discovery in
auto
mode (which is the case by default) creates a second client, and using any decorator client (flexible_client
,http_methods_client
orbatch_client
features) also involves creating additional services implementing the interface, so it is quite unlikely to work fine for them (and there is nothing we can do about except migrating to Symfony 3.3 to have the improved autowiring as fixing this case is one of the main improvements).We could do hacks to have this autowiring working in some cases, but the code would be quite ugly and would still have many cases where it would create WTF behaviors instead of the expected one. So I preferred not to support autowiring out of the box in Symfony < 3.3 instead.