Navigation Menu

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

Use Zend\Http\Client in Zend\Version #4625

Closed
wants to merge 2 commits into from
Closed

Use Zend\Http\Client in Zend\Version #4625

wants to merge 2 commits into from

Conversation

gws
Copy link
Contributor

@gws gws commented Jun 10, 2013

With this update, we can perform version checks without relying on the
environment having allow_url_fopen = 1.

We can now optionally pass in a Zend\Http\Client instance.

Tests were enhanced to run in a separate process to avoid problems during online
tests where tests would not actually be run because the class would cache the
first response, and subsequent responses would use that cached response.

This addresses #4610

@gws
Copy link
Contributor Author

gws commented Jun 11, 2013

Travis is failing on 5.3.3, but I think this is only because master is currently failing.

@tca3
Copy link
Contributor

tca3 commented Jun 11, 2013

Like @weierophinney said, it'd be better to detect the ini settings before forcing an http client to be used. I suppose it would cover both people having allow_fopen_url = "1" but no cURL support and those with allow_fopen_url = "0" with cURL support.

Then I guess it would return false (and a warning/exception ?) if neither file_get_contents or cURL is available.

@gws
Copy link
Contributor Author

gws commented Jun 11, 2013

He said

Alternately, or additionally, we should allow passing an HTTP client as a second argument to the method, which would allow you to continue to contact the service when the stream wrapper is unavailable.

This is "alternately," and it should cover everybody regardless of environment support.

@tca3
Copy link
Contributor

tca3 commented Jun 11, 2013

Well the file_get_contents method "covered everybody" but yet didn't always work depending your ini settings. Here, I can inject a client if I have no wrapper but the other way around doesn't work.

So I'd still be screwed if I had no cURL support but a working wrapper, which IMHO is the case of more people.

I'd be more in favor of

if (ini_get('allow_url_fopen') === '1' && $client === null) { 
    file_get_contents()
} 
else { 
    set default HTTP client or use the one passed in the arguments
}

@gws
Copy link
Contributor Author

gws commented Jun 11, 2013

Well the file_get_contents method "covered everybody" but yet didn't always work depending your ini settings.

So not everyone is covered - that's the reason for making this change in the first place. #4610

So I'd still be screwed if I had no cURL support but a working wrapper

How? Zend\Http\Client does not use cURL by default, it uses the Socket adapter, which should work for people without cURL (it should work for everyone).

fclose($handle);
}
}
if (null !== self::$latestVersion) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use static instead of self.

Copy link

Choose a reason for hiding this comment

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

self make more sense, because this class is marked as final, which means that this class cannot be extended.

@tca3
Copy link
Contributor

tca3 commented Jun 11, 2013

What I am saying is that issue #4610 is about handling the warning, not changing the implementation already in place. So the workflow would be: detect ini settings, trigger E_USER_WARNING if problem, then return false or proceed with Http\Client if it is set.

But if the client is relying on Socket, which I am not familiar with, then why not.

@gws
Copy link
Contributor Author

gws commented Jun 11, 2013

So the workflow would be: detect ini settings, trigger E_USER_WARNING if problem, then return false or proceed with Http\Client if it is set.

I see what you're saying. My thinking is that if we're already introducing the dependency on Zend\Http\Client as a fallback, we might as well go all in, which has two advantages: simplifies internal logic (over checking environment settings) and doesn't introduce an easily-avoidable warning or a BC break (a new return value, say false, would be).

@tca3
Copy link
Contributor

tca3 commented Jun 11, 2013

Makes sense, besides I just checked Socket and it seems to be handling everything internally already, so my bad :p . For the BC: it should have returned "not available" like it's done already.

@weierophinney
Copy link
Member

I'm going to be up-front and say that I'm a bit hesitant to add a dependency on zend-http to zend-version. At best, it should be optional: if no HTTP client is passed to the getLatest(), it should try to use streams, and emit a warning if it cannot do so. It should not create an instance, but only use one that is passed to it. (On the flip side, if an HTTP client is passed, it should always be used.)

@gws
Copy link
Contributor Author

gws commented Jun 12, 2013

@weierophinney Understood. Updated and tests added.

gws added 2 commits June 14, 2013 10:50
With this update, we can perform version checks without relying on the
environment having allow_url_fopen = 1.

You can now optionally pass in a Zend\Http\Client instance.

Tests are enhanced to run in a separate process to avoid problems during online
tests where tests would not actually be run because the class would cache the
first response, and subsequent responses would use that cached response.

- Emit helpful warning if allow_url_fopen is not set
- Split Github/Zend service calls into their own methods
- Early return cached version to reduce nesting
- Rename methods for consistency
- Consistent usage of self:: instead of static:: as the class is marked 'final'
*
* @return bool
*/
public static function isLatest()
{
return static::compareVersion(static::getLatest()) < 1;
return self::compareVersion(self::getLatest()) < 1;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you change static:: to self:: ?

static:: provides more flexibility for extending classes.

Copy link

Choose a reason for hiding this comment

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

This class cannot be extended, its a final class.

@ghost ghost assigned weierophinney Jun 28, 2013
weierophinney added a commit that referenced this pull request Jun 28, 2013
weierophinney added a commit that referenced this pull request Jun 28, 2013
@weierophinney
Copy link
Member

Merged to develop for release with 2.3.0 (as it introduces new features).

@gws gws deleted the use-http-client-in-zend-version branch June 28, 2013 17:54
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants