Skip to content
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

PSR-17 should be available to use Symfony's HttplugClient #150

Merged
merged 1 commit into from
Dec 16, 2019
Merged

PSR-17 should be available to use Symfony's HttplugClient #150

merged 1 commit into from
Dec 16, 2019

Conversation

mbabker
Copy link
Contributor

@mbabker mbabker commented Dec 4, 2019

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Related tickets fixes #149
Documentation N/A
License MIT

What's in this PR?

This is a bit of a stab in the dark, but I ran into the same problem in that issue and it seems like this PR should fix it.

Since #141 Symfony's Symfony\Component\HttpClient\HttplugClient is the first client class attempted when using auto-discovery, with its only condition being that that specific class is available (which is true if you have symfony/http-client >=4.4 installed). However, if you don't have anything which satisfies the PSR-17 auto discovery installed, then auto-discovery as a whole is going to fail because the Symfony class can't be instantiated.

This PR attempts to fix the issue by adding a condition on the PSR-17 interfaces being present as well. Looking at the Symfony app where I ran into the problem (Symfony 3.4 with the HttpClient component being pulled in as a transient dependency at 4.4), it seems like this would fix the problem because through that application's transient dependencies PSR-17 isn't installed so this condition should fail and it fall through to a working client (Guzzle in this application's case).

Checklist

  • Updated CHANGELOG.md to describe BC breaks / deprecations | new feature | bugfix
  • Documentation pull request created (if not simply a bugfix)

To Do

  • Is this the right way to address this issue?

@XWB
Copy link

XWB commented Dec 9, 2019

I can confirm that this change fixes #149

@dbu dbu requested a review from Nyholm December 9, 2019 15:22
@garak
Copy link

garak commented Dec 11, 2019

What about HttpAsyncClient? It should discover Symfony HttpClient too I see that it's in master. Hope to see a new release soon

@@ -72,7 +73,7 @@ final class CommonClassesStrategy implements DiscoveryStrategy
['class' => React::class, 'condition' => React::class],
],
HttpClient::class => [
['class' => SymfonyHttplug::class, 'condition' => SymfonyHttplug::class],
['class' => SymfonyHttplug::class, 'condition' => [SymfonyHttplug::class, Psr17RequestFactory::class]],
Copy link
Member

Choose a reason for hiding this comment

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

Won't this possibly break applications using HttpClient 4.3 where this was not necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The HttplugClient class that this is checking for doesn't exist in HttpClient 4.3 so it shouldn't be an issue.

Copy link
Member

@Nyholm Nyholm left a comment

Choose a reason for hiding this comment

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

Awesome. Thank you

@Nyholm Nyholm merged commit 4ebf4fa into php-http:master Dec 16, 2019
@Nyholm
Copy link
Member

Nyholm commented Dec 16, 2019

Ooops. I was too quick. It should be the message factory from HTTPlug.

@XWB
Copy link

XWB commented Dec 27, 2019

It looks like the fix was reverted by 4257709

Symfony 4.4 is still broken!

@dbu
Copy link
Contributor

dbu commented Dec 27, 2019

did you try with discovery 1.7.2? we had to fix checks to also look at interfaces and not only classes.

@mbabker mbabker deleted the patch-1 branch January 1, 2020 17:44
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.

Auto discovery broken in Symfony 4.4 ?
6 participants