-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #616 from bugsnag/default-guzzle-timeout
Add a default timeout & connect_timeout to Guzzle
- Loading branch information
Showing
7 changed files
with
177 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
|
||
namespace Bugsnag\Internal; | ||
|
||
use GuzzleHttp; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class GuzzleCompat | ||
{ | ||
/** | ||
* @return bool | ||
*/ | ||
public static function isUsingGuzzle5() | ||
{ | ||
if (defined(GuzzleHttp\ClientInterface::class.'::VERSION')) { | ||
$version = constant(GuzzleHttp\ClientInterface::class.'::VERSION'); | ||
|
||
return version_compare($version, '5.0.0', '>=') | ||
&& version_compare($version, '6.0.0', '<'); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* Get the base URL/URI option name, which depends on the Guzzle version. | ||
* | ||
* @return string | ||
*/ | ||
public static function getBaseUriOptionName() | ||
{ | ||
return self::isUsingGuzzle5() ? 'base_url' : 'base_uri'; | ||
} | ||
|
||
/** | ||
* Get the base URL/URI, which depends on the Guzzle version. | ||
* | ||
* @param GuzzleHttp\ClientInterface $guzzle | ||
* | ||
* @return mixed | ||
*/ | ||
public static function getBaseUri(GuzzleHttp\ClientInterface $guzzle) | ||
{ | ||
return self::isUsingGuzzle5() | ||
? $guzzle->getBaseUrl() | ||
: $guzzle->getConfig(self::getBaseUriOptionName()); | ||
} | ||
|
||
/** | ||
* Apply the given $requestOptions to the Guzzle $options array, if they are | ||
* not already set. | ||
* | ||
* The layout of request options differs in Guzzle 5 to 6/7; in Guzzle 5 | ||
* request options live in a 'defaults' array, but in 6/7 they are in the | ||
* top level | ||
* | ||
* @param array $options | ||
* @param array $requestOptions | ||
* | ||
* @return array | ||
*/ | ||
public static function applyRequestOptions(array $options, array $requestOptions) | ||
{ | ||
if (self::isUsingGuzzle5()) { | ||
if (!isset($options['defaults'])) { | ||
$options['defaults'] = []; | ||
} | ||
|
||
foreach ($requestOptions as $key => $value) { | ||
if (!isset($options['defaults'][$key])) { | ||
$options['defaults'][$key] = $value; | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
|
||
foreach ($requestOptions as $key => $value) { | ||
if (!isset($options[$key])) { | ||
$options[$key] = $value; | ||
} | ||
} | ||
|
||
return $options; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters