Skip to content
This repository has been archived by the owner on Jan 30, 2020. It is now read-only.

Lets allow users to set the HttpClient, #8

Closed
wants to merge 3 commits into from
Closed

Lets allow users to set the HttpClient, #8

wants to merge 3 commits into from

Conversation

harikt
Copy link
Contributor

@harikt harikt commented Oct 30, 2015

Which helps to make use of other methods .

Eg : findFeeds for I am using guzzle as http client.

@weierophinney
Copy link
Member

@harikt Can you please add tests for:

  • setHttpClient() with a mock Zend\Feed\Reader\Http\ClientInterface instance
  • getHttpClient() with each of mock Zend\Feed\Reader\Http\ClientInterface and Zend\Http\Client instances composed.

Also, I'd move the validation of the client against known types to setHttpClient(), so that we can ensure that the value is valid; that way, the check in getHttpClient() can be against null instead of the interface and/or concrete instance types.

@harikt
Copy link
Contributor Author

harikt commented Nov 3, 2015

I'd move the validation of the client against known types to setHttpClient()

My assumption is you are thinking of

public static function setHttpClient($httpClient)
{
    if (! $httpClient instanceof ZendHttp\Client || ! $httpClient instanceof ClientInterface) {
        throw InvalidClientException();
    }
    static::$httpClient = $httpClient;
}

If this is what you are thinking with validation, I did thought about it, but wonder if that change will bring any other issues to the sem version .

Thank you.

@harikt
Copy link
Contributor Author

harikt commented Nov 4, 2015

@weierophinney update with the changes asked.

Thank you.

@harikt
Copy link
Contributor Author

harikt commented Nov 11, 2015

any thoughts on this ?

@weierophinney
Copy link
Member

@harikt I'm reviewing this now, and feel it isn't going far enough. :)

Essentially, what I think we need to do is as follows:

  • We need to define an Http\ResponseInterface, with the following methods:
    • getStatusCode(), which is expected to return an integer status code.
    • getBody(), which is expected to return a string or an object that can serialize to a string.
      (ClientInterface already indicates it returns a ResponseInterface, but there's not one currently in that namespace, and none imported; adding one will actually make it complete finally. Interestingly, the above methods are common to both zend-http and PSR-7's response interfaces!)
  • We need to provide a zend-http response implementation; this can likely be a decorator or proxy class.
  • We need to provide a zend-http client implementation, which we can then use as the default if none is injected into the Reader. This should optionally expect a zend-http client instance to the constructor, creating an instance if none is provided, and delegate to it via the get() method. The returned response would be converted to the package-specific response type.
  • setHttpClient() should typehint on ClientInterface, ideally. However, for BC purposes, we can have it remove the typehint, and then internally check for either ClientInterface or a zend-http client; if the latter, it would pass it to the zend-http ClientInterface implementation from above.

These changes would make it more robust and forwards-compatible, I think, and very likely make it easier to create bridge implementations for other clients.

Question, @harikt — do you want to tackle these changes, or should I create a new PR incorporating this one to do it?

@harikt
Copy link
Contributor Author

harikt commented Nov 12, 2015

@weierophinney sure. Feel free to take this for I don't know when I can find some time to make the changes. If I noticed you haven't started and I am free, I will try to bring the PR.

Thank you.

@weierophinney
Copy link
Member

@harikt HA! we already have ResponseInterface defined, exactly as I detailed! That simplifies things!

I'm starting work on this immediately.

weierophinney added a commit to weierophinney/zend-feed that referenced this pull request Nov 12, 2015
Lets allow users to set the HttpClient,
@weierophinney
Copy link
Member

Closing in favor of #14, which extends the code introduced in this pull request with the featureset in my above comments.

mwillbanks added a commit that referenced this pull request Nov 20, 2015
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants