Skip to content

Commit

Permalink
Uses the Versions package to better determine the Guzzle version (#270)
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonmantank authored Dec 8, 2020
1 parent a01a7d4 commit 2148307
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,19 @@ public function __construct(CredentialsInterface $credentials, $options = [], ?C
if (is_null($client)) {
// Since the user did not pass a client, try and make a client
// using the Guzzle 6 adapter or Guzzle 7 (depending on availability)
/** @noinspection ClassConstantCanBeUsedInspection */
if (class_exists('\GuzzleHttp\Client')) {
$client = new \GuzzleHttp\Client();
} elseif (class_exists('\Http\Adapter\Guzzle6\Client')) {
list($guzzleVersion) = explode('@', Versions::getVersion('guzzlehttp/guzzle'), 1);
$guzzleVersion = (float) $guzzleVersion;

if ($guzzleVersion >= 6.0 && $guzzleVersion < 7) {
/** @noinspection CallableParameterUseCaseInTypeContextInspection */
/** @noinspection PhpUndefinedNamespaceInspection */
/** @noinspection PhpUndefinedClassInspection */
$client = new \Http\Adapter\Guzzle6\Client();
}

if ($guzzleVersion >= 7.0 && $guzzleVersion < 8.0) {
$client = new \GuzzleHttp\Client();
}
}

$this->setHttpClient($client);
Expand Down

0 comments on commit 2148307

Please sign in to comment.