mirror of
https://github.com/chillerlan/php-httpinterface.git
synced 2026-04-26 04:55:49 +03:00
[GH-ISSUE #4] Include a DiscoveryStategy for php-http/discovery #3
Labels
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/php-httpinterface#3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @eclipxe13 on GitHub (Mar 22, 2019).
Original GitHub issue: https://github.com/chillerlan/php-httpinterface/issues/4
Could you consider to add a
Http\Discovery\Strategy\DiscoveryStrategyimplementation so it would be easy to register and to use this library when working withphp-http/discovery?I just see that
php-http/discoveryknows about a very limited set of PSR-17, PSR-18 implementations. But has a way to add your classes to the discover process:This is a POC that I made and works once #3 is merged.
@codemasher commented on GitHub (Mar 22, 2019):
The original idea of httplug/
php-http/discoverywas to provide a common interface for http client libraries. Now that PSR-18 was accepted, it's no longer necessary to add another layer of abstraction.php-http/discoveryhas basically become obsolete now that we can write interoperable http clients usingPsr\Http\Client\ClientInterface- it's up to the implementors now. Aside of that, the majority of what i've seen is still using Guzzle directly.@eclipxe13 commented on GitHub (Mar 22, 2019):
I'm not talking about making
php-httpinterfacecompatible with HTTP interfaces of HTTP Plug.We have now PSR-17 & PSR-18 and its great. It makes obsolete while those PSR are commonly adopted.
But the discovery is filling a gap between the library user and the implementations provider. And this real need has not been covered by PHP-FIG.
php-http/discoverynow support discover PSR-18 implementations usingPsr18ClientDiscoveryand PSR-17 implementations usingPsr17FactoryDiscovery. They have also deprecated old methods that refer tophp-http/message-factoryandphp-http/client-implementation.As a developer of a component that relies on PSR7 & PSR17 & PSR18, it is easy to offer
php-http/discoverysupport, and if you include aDiscoveryStategyis easy to let users choose your library.On my side: I don't really care about what PSR implementation are they using.
On the library user's side: They have to do a minimal effort to use your library.
On your side: You provide a
php-http/discoveryway to use your library.Yes, the common libraries (symfony on the near future) have the majority of the users. But it should not be this way. It is not even sane.
I was thinking that this suggestion could be archived in another package.
Name it
chillerlan/php-httpinterface-discoverythat require onphp-http/discoverybut only suggestchillerlan/php-httpinterface. In that way, it can add strategies forPsr18ClientDiscoveryandPsr17ClientDiscoverybut will discover thechillerlan/php-httpinterfaceonly if it is installed.Also, in my library depending on
php-http/discoveryI can requirechillerlan/php-httpinterface-discoveryand suggestchillerlan/php-httpinterface, it won't installchillerlan/php-httpinterfaceby default but include more options to users.@codemasher commented on GitHub (Mar 22, 2019):
I get your point. However, it's not my goal to walk backwards. Users of existing libraries won't need this library - there are tons of others which will satisfy their needs and of which this library originated - namely: Guzzle, Slim, Nyholm. If someone's going to write a new library that needs a http client, they'll probably prefer a PSR-18 client over a non-standard implementation anyway - without the need for lazy-loading or anything. If they're going to prefer the non-standard, it's up to them to provide an adapter for other client libraries in case they want them to be used (been there). I prefer not to contribute to technical debt and go with the standards we're given. Feel free to provide a
php-http/discoveryadapter for my library on your own - nothing will stop you.@eclipxe13 commented on GitHub (Mar 22, 2019):
Ok, I will not insist on this. But I think you are missing the point that this is provide only standards.
They could, existing libraries based on HTTP Plug are obsolete now by HTTP Plug itself, and they will search for PSR compliant code as HTTP Plug is moving in that way.
This suggestion is to have more clients on PSR-17 & PSR-18 available. This is not going backwards and as you can see in the example code, is promoting only PSR-17 & PSR-18, is not promoting any non-PSR or HTTP Plug interfaces.
In my case, as a library creator, I will not use a direct implementation of PSR-17/PSR-18. Except, of course, for testing. All that should be configured by user. One way to achieve this is using
php-http/discovery.php-http/discoverydoes not force you to use any of the old HTTP Plug Interfaces that are now deprecated.Thank you for your time and your thoughts.
@codemasher commented on GitHub (Mar 22, 2019):
I still don't get the whole point of lazy loading a http client library - for Message factories, i can understand - these have strictly defined functionality. PSR-18 only provides
sendRequest()- the rest is completely up to the http client library, that may require settings and all, making the point of a client discovery extremely wonky. Provide the http client of your choice - fin.Edit: i'm pretty sure that was the point to not include some kind of discovery in PSR-18.