Skip to content

Commit

Permalink
More cleanup of creating a default handler
Browse files Browse the repository at this point in the history
  • Loading branch information
mtdowling committed Feb 8, 2015
1 parent 64958c1 commit 646ca53
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function __construct(array $config = [])
*/
public static function getDefaultHandler()
{
$default = $future = $streaming = null;
$default = $future = null;

if (extension_loaded('curl')) {
$config = [
Expand All @@ -111,30 +111,24 @@ public static function getDefaultHandler()
if ($maxHandles = getenv('GUZZLE_CURL_MAX_HANDLES')) {
$config['max_handles'] = $maxHandles;
}
$default = $future = new CurlMultiHandler($config);
if (function_exists('curl_reset')) {
$default = new CurlHandler();
$future = new CurlMultiHandler($config);
} else {
$default = new CurlMultiHandler($config);
}
}

if (ini_get('allow_url_fopen')) {
$streaming = new StreamHandler();
if (!$default) {
$default = $streaming;
}
}

if (!$default) {
$default = !$default
? new StreamHandler()
: Middleware::wrapStreaming($default, new StreamHandler());
} elseif (!$default) {
throw new \RuntimeException('Guzzle requires cURL, the '
. 'allow_url_fopen ini setting, or a custom HTTP handler.');
}

$handler = $default;
if ($streaming && $streaming !== $default) {
$handler = Middleware::wrapStreaming($default, $streaming);
}

return $future ? Middleware::wrapFuture($handler, $future) : $handler;
return $future ? Middleware::wrapFuture($default, $future) : $default;
}

/**
Expand Down

0 comments on commit 646ca53

Please sign in to comment.