Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 9f7101c

Browse files
authored
Merge pull request #591 from commercetools/guzzle7
Closes #590
2 parents 38ffd9a + 4c371e6 commit 9f7101c

File tree

14 files changed

+118
-24
lines changed

14 files changed

+118
-24
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"require": {
3333
"php": ">=5.6",
3434
"psr/log": "^1.0",
35-
"guzzlehttp/guzzle": "^6.0 || ^5.3.3",
35+
"guzzlehttp/guzzle": "^7.0 || ^6.0 || ^5.3.3 ",
3636
"guzzlehttp/psr7": "^1.1",
3737
"psr/cache": "^1.0",
3838
"psr/simple-cache": "^1.0",
@@ -41,7 +41,7 @@
4141
"ext-intl": "*"
4242
},
4343
"require-dev": {
44-
"guzzlehttp/guzzle": "^6.0",
44+
"guzzlehttp/guzzle": "^7.0 || ^6.0",
4545
"phpunit/phpunit": "^8.5",
4646
"symplify/easy-coding-standard": "^7.2",
4747
"doctrine/cache": "^1.6",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "commercetools-php-sdk-changelog",
3-
"version": "3.0.0",
3+
"version": "2.12.0",
44
"description": "commercetools PHP SDK changelog generator package description",
55
"homepage": "https://github.com/commercetools/commercetools-php-sdk",
66
"bugs": "https://github.com/commercetools/commercetools-php-sdk/issues",

set_guzzle5.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
2-
SRC='"guzzlehttp/guzzle": "^6.0"'
2+
SRC='"guzzlehttp/guzzle": "^7.0 \|\| ^6.0"'
33
DST='"guzzlehttp/guzzle": "^5.3.3", "react/promise": "^2.2.0", "guzzlehttp/ringphp": "^1.1.1"'
44
sed -ibak -e "s|$SRC|$DST|g" composer.json

src/Core/AbstractHttpClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
abstract class AbstractHttpClient
1616
{
17-
const VERSION = '3.0.0-dev';
17+
const VERSION = '2.12.0-dev';
1818

1919
/**
2020
* @var AdapterInterface

src/Core/Client/Adapter/AdapterFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
use GuzzleHttp\Client;
99
use Commercetools\Core\Error\InvalidArgumentException;
10+
use GuzzleHttp\ClientInterface;
1011

1112
class AdapterFactory
1213
{
@@ -38,7 +39,9 @@ public function register($name, $adapterClass)
3839
public function getClass($name = null)
3940
{
4041
if (is_null($name)) {
41-
if (version_compare(Client::VERSION, '6.0.0', '>=')) {
42+
if (defined('\GuzzleHttp\ClientInterface::MAJOR_VERSION')) {
43+
$name = 'guzzle6';
44+
} elseif (version_compare(Client::class . '::VERSION', '6.0.0', '>=')) {
4245
$name = 'guzzle6';
4346
} else {
4447
$name = 'guzzle5';

src/Core/Client/Adapter/Guzzle6Adapter.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
use Commercetools\Core\Helper\CorrelationIdProvider;
1111
use Commercetools\Core\Response\AbstractApiResponse;
1212
use GuzzleHttp\Client;
13+
use GuzzleHttp\ClientInterface;
14+
use GuzzleHttp\Exception\GuzzleException;
1315
use GuzzleHttp\Exception\RequestException;
16+
use GuzzleHttp\Exception\TransferException;
1417
use GuzzleHttp\HandlerStack;
1518
use GuzzleHttp\MessageFormatter;
1619
use GuzzleHttp\Middleware;
@@ -154,6 +157,8 @@ public function execute(RequestInterface $request, array $clientOptions = [])
154157
} catch (RequestException $exception) {
155158
$response = $exception->getResponse();
156159
throw ApiException::create($request, $response, $exception);
160+
} catch (TransferException $exception) {
161+
throw ApiException::create($request, null, $exception);
157162
}
158163

159164
return $response;
@@ -182,7 +187,11 @@ public function executeBatch(array $requests, array $clientOptions = [])
182187
$request = $requests[$key];
183188
$httpResponse = $result->getResponse();
184189
$httpResponse = ApiException::create($request, $httpResponse, $result);
190+
} elseif ($result instanceof TransferException) {
191+
$request = $requests[$key];
192+
$httpResponse = ApiException::create($request, null, $result);
185193
}
194+
186195
$responses[$key] = $httpResponse;
187196
}
188197

@@ -225,7 +234,12 @@ public function executeAsync(RequestInterface $request, array $clientOptions = [
225234

226235
public static function getAdapterInfo()
227236
{
228-
return 'GuzzleHttp/' . Client::VERSION;
237+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
238+
$clientVersion = (string) constant(Client::class . '::MAJOR_VERSION');
239+
} else {
240+
$clientVersion = (string) constant(Client::class . '::VERSION');
241+
}
242+
return 'GuzzleHttp/' . $clientVersion;
229243
}
230244

231245
/**

src/Core/Client/ClientFactory.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Commercetools\Core\Model\Common\ContextAwareInterface;
2020
use Commercetools\Core\Response\AbstractApiResponse;
2121
use GuzzleHttp\Client;
22+
use GuzzleHttp\Client as HttpClient;
2223
use GuzzleHttp\Exception\RequestException;
2324
use GuzzleHttp\HandlerStack;
2425
use GuzzleHttp\MessageFormatter;
@@ -582,7 +583,12 @@ function ($reason) use ($logger, $request, $formatter) {
582583
private static function isGuzzle6()
583584
{
584585
if (is_null(self::$isGuzzle6)) {
585-
if (version_compare(Client::VERSION, '6.0.0', '>=')) {
586+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
587+
$clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
588+
} else {
589+
$clientVersion = (string) constant(HttpClient::class . '::VERSION');
590+
}
591+
if (version_compare($clientVersion, '6.0.0', '>=')) {
586592
self::$isGuzzle6 = true;
587593
} else {
588594
self::$isGuzzle6 = false;

src/Core/Client/UserAgentProvider.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ public function getUserAgent()
3737

3838
private function getAdapterInfo()
3939
{
40-
return 'GuzzleHttp/' . HttpClient::VERSION;
40+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
41+
$clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
42+
} else {
43+
$clientVersion = (string) constant(HttpClient::class . '::VERSION');
44+
}
45+
return 'GuzzleHttp/' . $clientVersion;
4146
}
4247
}

tests/integration/ClientTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Commercetools\Core\Model\Project\Project;
1414
use Commercetools\Core\Request\Project\ProjectGetRequest;
1515
use Commercetools\Core\Response\AbstractApiResponse;
16+
use GuzzleHttp\Client as HttpClient;
1617
use GuzzleHttp\HandlerStack;
1718
use Monolog\Handler\TestHandler;
1819
use Monolog\Logger;
@@ -48,7 +49,12 @@ public function testCorrelationId()
4849

4950
public function testCustomHandlerStack()
5051
{
51-
if (version_compare(\GuzzleHttp\Client::VERSION, '6.0.0', '<')) {
52+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
53+
$clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
54+
} else {
55+
$clientVersion = (string) constant(HttpClient::class . '::VERSION');
56+
}
57+
if (version_compare($clientVersion, '6.0.0', '<')) {
5258
$this->markTestSkipped("Only valid for Guzzle version < 6");
5359
}
5460

tests/unit/Client/OAuth/ManagerTest.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Commercetools\Core\Cache\CacheAdapterFactory;
1313
use Commercetools\Core\Client\Adapter\ConfigAware;
1414
use Commercetools\Core\Error\InvalidClientCredentialsException;
15+
use GuzzleHttp\Client;
1516
use GuzzleHttp\Client as HttpClient;
1617
use GuzzleHttp\Handler\MockHandler;
1718
use GuzzleHttp\HandlerStack;
@@ -57,7 +58,12 @@ protected function getManager($config, $returnValue, $statusCode = 200, $noCache
5758
$returnValue = json_encode($returnValue);
5859
}
5960

60-
if (version_compare(HttpClient::VERSION, '6.0.0', '>=')) {
61+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
62+
$clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
63+
} else {
64+
$clientVersion = (string) constant(HttpClient::class . '::VERSION');
65+
}
66+
if (version_compare($clientVersion, '6.0.0', '>=')) {
6167
$mockBody = new BufferStream();
6268
$mockBody->write($returnValue);
6369

@@ -284,7 +290,12 @@ public function testOAuthUrl()
284290

285291
public function testSetClientOptions()
286292
{
287-
if (version_compare(HttpClient::VERSION, '6.0.0', '>=')) {
293+
if (defined('\GuzzleHttp\Client::MAJOR_VERSION')) {
294+
$clientVersion = (string) constant(HttpClient::class . '::MAJOR_VERSION');
295+
} else {
296+
$clientVersion = (string) constant(HttpClient::class . '::VERSION');
297+
}
298+
if (version_compare($clientVersion, '6.0.0', '>=')) {
288299
$clientOptions = ['verify' => false];
289300
} else {
290301
$clientOptions = ['defaults' => ['verify' => false]];

0 commit comments

Comments
 (0)