Skip to content

Commit

Permalink
Fix Guzzle version detection
Browse files Browse the repository at this point in the history
  • Loading branch information
voronkovich committed Aug 29, 2021
1 parent 3f02051 commit bf9c12e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/HttpClient/GuzzleAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,23 @@
class GuzzleAdapter implements HttpClientInterface
{
private $client;
private $version;

public function __construct(ClientInterface $client)
{
$this->client = $client;

$class = \get_class($client);

if (\defined($class.'::MAJOR_VERSION')) {
$this->version = (int) $client::MAJOR_VERSION;
} elseif (\defined($class.'::VERSION')) {
$this->version = (int) $client::VERSION;
}
}

public function request(string $uri, string $method = HttpClientInterface::METHOD_GET, array $headers = [], string $data = ''): array
{
$guzzleVersion = (int) $this->client::VERSION;

$options = ['headers' => $headers];

switch ($method) {
Expand All @@ -47,7 +54,7 @@ public function request(string $uri, string $method = HttpClientInterface::METHO
break;
}

if (6 > $guzzleVersion) {
if (6 > $this->version) {
$request = $this->client->createRequest($method, $uri, $options);
$response = $this->client->send($request);
} else {
Expand Down

0 comments on commit bf9c12e

Please sign in to comment.