Skip to content

Use ClientInterface instead of HttpClient interface when registering aliases #394

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

Merged
merged 3 commits into from
Jul 26, 2021

Conversation

ruudk
Copy link
Contributor

@ruudk ruudk commented Jul 12, 2021

Q A
Bug fix? no
New feature? no
BC breaks? no
Deprecations? yes
Related tickets
Documentation if this is a new feature, link to pull request in https://github.com/php-http/documentation that adds relevant documentation
License MIT

What's in this PR?

After #393 was merged I started using it in my project and soon discovered that HttpClient is deprecated and that the ClientInterface from Psr should be used instead.

Why?

This will deprecate the alias registration for HttpClient when the ClientInterface is found.

It will also register the alias for the ClientInterface.

@ruudk ruudk changed the title Use ClientInterface instead of HttpClient interface Use ClientInterface instead of HttpClient interface when registering aliases Jul 12, 2021
Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the update and sorry for the late reply - i was on holidays last week.

i agree we should do this. however, i am a bit worried about creating false deprecations and wiring the psr interface if somebody manages to install this change along with the psr client but an old version of httplug.

@@ -382,7 +383,12 @@ private function configureClient(ContainerBuilder $container, $clientName, array
$serviceId = 'httplug.client.'.$clientName;

if (method_exists($container, 'registerAliasForArgument')) {
$container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
$alias = $container->registerAliasForArgument($serviceId, HttpClient::class, $clientName);
if (interface_exists(ClientInterface::class)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think the existence of the psr interface is not the correct way to know which version of httplug we are using. we should additionally check if the httplug client implements the psr interface or something else that tells us if we are installed with a httplug version that implements the interface.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does 0006ec2 solve it?

Copy link
Collaborator

@dbu dbu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, this looks robust to me!

@dbu dbu merged commit 79501e9 into php-http:master Jul 26, 2021
@dbu
Copy link
Collaborator

dbu commented Jul 26, 2021

@ruudk ruudk deleted the use-client-interface branch July 26, 2021 08:30

$interfaces = class_implements(HttpClient::class) ?? [];
if (isset($interfaces[ClientInterface::class])) {
$alias->setDeprecated('php-http/httplug-bundle', '1.22', 'The "%alias_id%" alias is deprecated, use "Psr\Http\Client\ClientInterface" instead.');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ruudk somebody reported that symfony complains about the deprecation warning, saying it needs an %alias_id% (though i see that here)... https://twitter.com/PP_Vortex/status/1419599426084032519

can you please check if the deprecation warning works correctly for you and there is no symfony warning about alias_id?

Copy link

@franziskahahn franziskahahn Jul 26, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some deep dive into vendors and found out the following fact:

the method setDeprecated in Alias.php changed in symfony 5.3 compared to symfony 4.4:
https://github.com/symfony/dependency-injection/blob/5.3/Alias.php
https://github.com/symfony/dependency-injection/blob/4.4/Alias.php

In symfony 4.4, the second parameter is the template. So when using http plug bundle with symfony 4.4 executing assets:install interpretes this line as "deprecation template is '1.22'" and this string obviously doesn't contain %alias_id%.

$alias->setDeprecated('php-http/httplug-bundle', '1.22', 'The "%alias_id%" alias is deprecated, use "Psr\Http\Client\ClientInterface" instead.'); is fine for symfony 5.3 but not for symfony 4.4

My conclusion: Currently, php-http/httplug-bundle 1.22 is not compatible with symfony 4.4 but seems to be compatible with symfony 5.3

What would be the next steps here? Would you like to be compatible with both versions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll check it out and make a PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #396

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for reporting the issue and for the analysis @franziskahahn. the deprecation is removed in https://github.com/php-http/HttplugBundle/releases/tag/1.22.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants