From bf9c12e7bae7ebc2710bcd082245fcfc659daeab Mon Sep 17 00:00:00 2001 From: Oleg Voronkovich Date: Sun, 29 Aug 2021 22:23:37 +0300 Subject: [PATCH] Fix Guzzle version detection --- src/HttpClient/GuzzleAdapter.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/HttpClient/GuzzleAdapter.php b/src/HttpClient/GuzzleAdapter.php index f4fb970..2d94850 100644 --- a/src/HttpClient/GuzzleAdapter.php +++ b/src/HttpClient/GuzzleAdapter.php @@ -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) { @@ -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 {