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
[3.0] PSR-7 Messages #320
Comments
|
Hmm, so okay, not really anymore. See the PR in thephpleague/omnipay-common#74 Just a Simplest would be just Also, instead of decorating the respones, better just a |
Now leaning more towards http://php-http.readthedocs.org/en/latest/index.html |
What's the word on the street about HTTPPlug? Is there a feeling it may become a PSR? I like the idea. Whether we decorate/extend PSR-7 messages, or provide help functions to make dealing with vanilla PSR-7 messages a little simpler, I personally have no preference to. The aim, IMO, is to avoid having to make each gateway duplicate the same features (naturally, each in slightly different ways, and with their own issues to work through). So I'm easy on that one. |
I'd actually not heard of HTTPPlug before and I'm not 100% sure how I feel about that. I am a fan of pulling in PSR-7, though. A lot of apps are going that way and it will make us easy and agnostic to use. I've been using PSR-7 at work for some time with Zend-Diactoros. You're right @barryvdh about less than pretty interface (and very confusing at first, IMO), but I think it's worth using and taking it upon ourselves to make it pretty when/if we need to. We've already decided to bump the Guzzle version we're using for V3, so we can just go straight to Guzzle 6. |
So what kind of interface do you suggest? Remove the |
What's the benefit of having them separated like that? |
That was to allow extra modifications to the request object, but not sure if we actually need that. |
For example, for Authorization headers. You could want to do something like this, if you create a function or use a PSR-7 library: $request = $client->createRequest('GET', 'http://example.com/purchase');
$request = $this->addOAuthHeaders($request);
$client->sendRequest($request); |
A question on the HTTP client - is OmniPay 3.0 going to be locked to a version of Guzzle, like OmniPay 2.x is? I thought the idea was to be HTTP client agnostic, with PSR-7 messages being a part of enabling that? The fact that Guzzle baked into 2.x now, is holding back lots of people from using OmniPay in some frameworks, so I'm not sure why we would want to go down that route again. |
No, because the gateways rely on our HTTP interface and the psr objects. We can create a Guzzle7 or some other lib, as long as it uses PSR7. We just supply a default client with zero configuration, so we could change it later on. |
Not sure I understand which bit is "no". Is Guzzle just going to be a |
We require guzzle, but its not a public api, so we can change it to a new/other library. |
But somebody using OmniPay can't change it? That's my point. If Guzzle of a certain version is required, then that sets Guzzle for the whole environment that OmniPay is used in. That throws away the main advantage of PSR-7 in that no specific HTTP client or version should be required. ANY PSR-7 client could be used. |
So what do you suggest, no default client? |
An OmniPay client with an adapter for Guzzle. |
That could make it more difficult to install. People need to require an extra package for the client, instantiate their own client and pass it on to Omnipay etc. |
Yes sure, if they want to use their own client. If they don't pass in their own client, then OmniPay can check if Guzzle is installed, then use its own if it is. |
I kind of understand you're issue. But currently Guzzle is by far the most used library for this. We should avoid making a hard dependecy out of Guzzle, but I don't think we should leave this completely open. If Guzzle upgrades, it would be reasonably to suspect that they will follow the PSR-7 standard still, so we can update the library. The only problem would be people who instantiate our Guzzle Http client on their own. So options are:
Option 3 is what we sort of do now (create a default client with zero config), if we just make that clear in the docs, I think it shouldn't really be a problem imho. |
Implemented |
So as discussed in #274, we should probably move to PSR-7 instead of Guzzle request/responses. And probably also instead of the http foundation.
Pros:
Cons
So what to do? Decorators and factories have been suggested. One solution could be to mimic the old httpclient / httprequest, or at least the most common functionality. Examples:
Decorated ServerRequestInterface
Currently the request is mostly used to get request (post) and query (get) variables. This isn't as pretty in PSR-7 (
$request->getQueryParams()[$key]
), could be$request->query($key, $default)
. Same goes for Request and perhaps a referrer/IP from the headers.Decorated ResponseInterface
The response is pretty basic and also not pretty.
$response->json()
and$response->xml()
could be added back.HttpClient
Currently creates a Guzzle Request, with send() method. Could be changed to return a PSR-7 request, which can be sent with the client
sendRequest($psr7request)
, could return a decorated response object.get($url, $headers)
,post($uri, $headers, $body)
etc, could return a PSR-7 request, or could be sent directly (like in v2) and return a decorated response.These helpers would probably work for 90% of the time, the rest of the time the original PSR message could be used.
The text was updated successfully, but these errors were encountered: