-
Notifications
You must be signed in to change notification settings - Fork 39
Terminology #40
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
Terminology #40
Conversation
@hannesvdvreken FYI |
@sagikazarmark I'm watching this repo so saw the PR ;-) I'll have a look tomorrow. |
Well, my personal experience is that people tend to look at Github messages more actively if they are specifically mentioned. 😉 Sure, no hurry. |
I've gone through the changes quickly and I think it's very clear now. The adapter packages just implement the PsrHttpClient interface, right? There will be a HttpClient and a Client class which wraps a PsrHttpClient and provides the interfaces and still expose the PsrHttpClient methods. Didn't take an in depth look to find mistakes because time constraints, but I thrust it will be close to perfect ;-) |
Basically, yes.
The plan is to have something called adapter client which is a wrapper around a PsrHttpClient and yes, still implements it. Something like: class AdapterClient implements Client
{
public function __construct(PsrHttpClient $psrHttpClient) {}
} |
b0d2833
to
688f737
Compare
@hannesvdvreken thanks for feedback. What do you think about the TODOs I mentioned in the issue description? |
use Psr\Http\Message\ResponseInterface; | ||
|
||
/** | ||
* Interface for HTTP conventional methods |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe say "Interface for HTTP requests without the PSR-7 RequestInterface"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm. Sounds good, but does it really explain what this interface is about? The point is rather about HTTP methods than the lack of RequestInterface.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then maybe just add a second line saying: "Use this interface when you do not have PSR-7 RequestInterface instances available."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Another major change I am thinking about: currently post, put, patch, delete and options request in HttpClient have two type of body fields:
Furthermore, if I see the reasoning behind, it was hard for @egeloen to create an easy, but full solution. It is still a little bit weird, so I am thinking about the following: I would create a Body interface with the following implementations:
With the exception of Stream these objects would be string castable which can be used then to create a Stream object. This is obviously extra complexity, but I came up with the idea, because I think it can be confusing this way as well. Also, much of the body creating logic can be moved to the Body classes and the client should only handle string to stream conversion. What do you think? |
Let's continue the body discussion in #42 |
@dbu Ideas for ClientTemplate naming? HttpMethods for example? Since it only "implements" the HTTP methods, |
HttpMethodsClient as interface and HttpMethods as trait sounds good to me.
|
#26 should also be addressed here. |
Add Body implementations Remove Data body interface, common interface is not needed Add Content headers to Body Body is optional, add HttpMethods trait Refactored body implementations
Add Body implementations
Sorry to chime in so late, but I have some doubts about the mix between interfaces and ‘convenience’ classes such as those in the |
The Body classes are supposed to replace the InternalRequest object in Ivory. The point is that you can use these clases to provide custom type data (like files) to the convenience method calls. They are completely optional and can be translated into an array of content headers and a string which then can be passed to the message factory. Guzzle 6 adapter probably won't need it, as they are related to the convenience methods, adapters does not need to implement those. I plan to create a separate "adapter/client" for that which accepts an HttpPsrClient and implements HttpMethodsClient. |
That they are optional is exactly the problem that I have with them. The Body classes have mostly to do with messages, don't they? In that case, they could go into a separate message package that only clients that need them depend on. |
The Body interface is part of the contract, it is used in HttpMethodsClient. The basic implementations provided are small. That said, it is still implementation and you might be right about moving them into a utility package. There is another BatchRequest trait work in progress which is also something like that. My only concern about it is in that case the utility package must require the contract, which in turn can lead to a dependency hell: an adapter/client requires both the contract and the utility. If versions doesn't match, you can't install the adapter. |
Add sendRequests method as a trait
i think the utility repo becomes more and more of a thing. everything
not part of the contract should not be in this repo.
dependency is a thing we need to be careful about anyways. we can't
change anything in an interface in the contract without bumping the
major version. which is something we should be very careful to avoid doing.
the utility is not making the problem worse. it will just have a minimum
requirement of the major version of the client, and every adapter should
trust both utils and contract to be proper semver, that is accept any
minor version that is new enough for it.
even if we bump the contract, the utilities might not need to bump their
major version if what they do is not affected.
|
I hope that major version bumps will be extremely rare, so we might not even face this dependency hell issue we are afraid from. The only condition is to have well-designed interfaces, which we are working on right now. |
IMO we can leave utility classes in this package (client), as if they are not used they don't add anything expect for the disk size. |
Yes, they do. Bandwidth, package complexity, autoloading. These are minor things, but imagine the package installed a thousand times. |
Any last words before merging this one? |
Let's continue the utility discussion in #56 |
Make custom SPL exception extensions final
I think this can be merged, anyways it's an alpha release and there is still room for other alpha release if big change come up with new discussions |
A remark about the Body, if it is split into an Utility package, all adapter implementing the HttpMethodsClient interface will then have to depend on this package ? |
Nope. The Body interface remains in this package. Optionally the implementations should be moved to the utility package. |
/** | ||
* Convert data to a format which can be used to create a proper PSR-7 Stream | ||
* | ||
* @return string|StreamInterface |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PSR7 Only allow StreamInterface no string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, string is a valid return type here as well. Keep in mind that this interface is used in the MethodsClient where you probably use a MessageFactory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes but it may conflict with some implementations like diactoros where the string is an url to stream and not a content. But maybe the string here as the same purpose ? In this case we should add documentation about the string return value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have a custom MessageFactory interface which is recommended to be used. This ensures you can use whatever PSR7 implementation in your clients. There is already some kind of documentation about it, for reference check the docs repo.
Presonally I think that the diactoros behavior is a bit weird. I think using string as a simple body is much more logical than using it as a URL to a stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, i'm working on the socket adapter right now and using diactoros (only for the init puprose) feel weirds when implementing the send method :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check the docs here: http://php-http.readthedocs.org/en/latest/
We have a zero-config discovery service which let you just use the available implementation AND message factory.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nonetheless we should explain what the string we allow to return here is. if we allow a string at all - it seems like an ambiguity. ideally we would even eliminate string as return completely. otherwise a consumer needs to check whether it got a string or a stream and do different things...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have already discussed this in another issue. Body objects would need a message factory to return a stream object. And that's one simple IF to check the input parameter.
The alternative is to remove body types entirely and use "generators" which can populate the request based on a specific input. It would certainly make the contract cleaner. And we could move that code to the utility package.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would also mean, that requests sent through HttpMethodsClient must be populated from the generator manually.
* | ||
* @return string|StreamInterface | ||
* | ||
* @throws Exception |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this being an interface we could also say what circumstances might typically lead to exceptions.
POC how to not be dependent on discovery Fix unit tests Fix factory method Remove duplicated service Move discovery to compiler pass Applied fixes from StyleCI Fix puli executable Use class constant Fix puli command order Fix lowest dependency issue Fix HHVM tests Improve tests
This PR tries to solve #38
Some points to discuss:
To do before merging:
Squash commits!!!!!!!To do after merging: