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

Commit b7bc182

Browse files
author
Jens Schulze
committed
Merge branch 'release/v2.2.0'
2 parents 44676fc + 31cbf73 commit b7bc182

File tree

148 files changed

+3840
-142
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+3840
-142
lines changed

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ before_script:
3333
- if [ $GUZZLE != '5' ] ; then composer install -o --prefer-dist; fi
3434
script:
3535
- ant phpcs-ci
36-
- vendor/bin/phpunit --testsuite=unit
36+
- if [ $GUZZLE == '5' ] || [ $PHP == '5.6' ] || [ $PHP == 'hhvm' ] ; then vendor/bin/phpunit -c phpunit5.xml.dist --testsuite=unit; fi
37+
- if [ $GUZZLE == '6' ] && [ $PHP != '5.6' ] ; then vendor/bin/phpunit --testsuite=unit; fi
3738
- if [ $PHP == '7.0' ] && [ $GUZZLE == '6' ] ; then vendor/bin/phpunit --testsuite=integration; fi
3839
- ant behat
3940
after_success:

CHANGELOG.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,36 @@
1+
<a name="2.2.0"></a>
2+
# [2.2.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.1.0...v2.2.0) (2017-09-27)
3+
4+
5+
### Bug Fixes
6+
7+
* **Me:** fix MeUpdateRequest constructor ([e96a2d1](https://github.com/commercetools/commercetools-php-sdk/commit/e96a2d1))
8+
* **Message:** fix object hierarchy for PaymentTransactionStateChanged message ([b4ec4a2](https://github.com/commercetools/commercetools-php-sdk/commit/b4ec4a2))
9+
* **StateTransitionMessage:** fix type of state in StateTransitionMessage ([2bb1efd](https://github.com/commercetools/commercetools-php-sdk/commit/2bb1efd))
10+
11+
12+
### Features
13+
14+
* **Cart:** support add line item by sky ([3b81973](https://github.com/commercetools/commercetools-php-sdk/commit/3b81973)), closes [#341](https://github.com/commercetools/commercetools-php-sdk/issues/341)
15+
* **Cart:** support external tax amount ([95e5547](https://github.com/commercetools/commercetools-php-sdk/commit/95e5547)), closes [#347](https://github.com/commercetools/commercetools-php-sdk/issues/347)
16+
* **Cart:** support setAnonymousId ([1a1e472](https://github.com/commercetools/commercetools-php-sdk/commit/1a1e472)), closes [#338](https://github.com/commercetools/commercetools-php-sdk/issues/338)
17+
* **Cart:** support setCustomerGroup update action ([80c72ec](https://github.com/commercetools/commercetools-php-sdk/commit/80c72ec)), closes [#343](https://github.com/commercetools/commercetools-php-sdk/issues/343)
18+
* **Client:** add configuration options for guzzle ([18dbd00](https://github.com/commercetools/commercetools-php-sdk/commit/18dbd00)), closes [#345](https://github.com/commercetools/commercetools-php-sdk/issues/345)
19+
* **Client:** support creation of correlation id at client side ([124c004](https://github.com/commercetools/commercetools-php-sdk/commit/124c004)), closes [#328](https://github.com/commercetools/commercetools-php-sdk/issues/328)
20+
* **CustomField:** add type safe getter for field in field container ([732f861](https://github.com/commercetools/commercetools-php-sdk/commit/732f861))
21+
* **Customer:** support setKey for customers ([211573d](https://github.com/commercetools/commercetools-php-sdk/commit/211573d)), closes [#342](https://github.com/commercetools/commercetools-php-sdk/issues/342)
22+
* **CustomerGroup:** support field `key` functionality ([57e803c](https://github.com/commercetools/commercetools-php-sdk/commit/57e803c)), closes [#330](https://github.com/commercetools/commercetools-php-sdk/issues/330)
23+
* **Message:** add ProductVariantDeleted, ProductDeleted and ProductRevertedStagedChanges message ([f7291ae](https://github.com/commercetools/commercetools-php-sdk/commit/f7291ae)), closes [#332](https://github.com/commercetools/commercetools-php-sdk/issues/332)
24+
* **Product:** add typed getter for product attribute value ([34afcdd](https://github.com/commercetools/commercetools-php-sdk/commit/34afcdd))
25+
* **Product:** support scope for product publish ([9d0b5aa](https://github.com/commercetools/commercetools-php-sdk/commit/9d0b5aa)), closes [#340](https://github.com/commercetools/commercetools-php-sdk/issues/340)
26+
* **Project:** support change of project settings ([347ecb6](https://github.com/commercetools/commercetools-php-sdk/commit/347ecb6)), closes [#350](https://github.com/commercetools/commercetools-php-sdk/issues/350)
27+
* **ShippingMethod:** add support for shipping method predicate ([19ea63e](https://github.com/commercetools/commercetools-php-sdk/commit/19ea63e)), closes [#348](https://github.com/commercetools/commercetools-php-sdk/issues/348)
28+
* **ShippingMethod:** support shipping method by key functionality ([3ba9596](https://github.com/commercetools/commercetools-php-sdk/commit/3ba9596)), closes [#329](https://github.com/commercetools/commercetools-php-sdk/issues/329)
29+
* **Subscription:** support azure service bus destination ([58ad977](https://github.com/commercetools/commercetools-php-sdk/commit/58ad977)), closes [#331](https://github.com/commercetools/commercetools-php-sdk/issues/331)
30+
* **TaxCategory:** support setKey for tax categories ([6c41b97](https://github.com/commercetools/commercetools-php-sdk/commit/6c41b97)), closes [#339](https://github.com/commercetools/commercetools-php-sdk/issues/339)
31+
32+
33+
134
<a name="2.1.0"></a>
235
# [2.1.0](https://github.com/commercetools/commercetools-php-sdk/compare/v2.0.0...v2.1.0) (2017-07-06)
336

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ curl -sS https://getcomposer.org/installer | php
3030
Next, run the Composer command to install the latest version of the SDK:
3131

3232
```bash
33-
composer require commercetools/php-sdk dev-master
33+
composer require commercetools/php-sdk
3434
```
3535

3636
The SDK supports Guzzle6 as well as Guzzle5 as HTTP client. For Guzzle6:

composer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,13 @@
3535
"psr/cache": "^1.0",
3636
"psr/simple-cache": "^1.0",
3737
"cache/apcu-adapter": "^0.2",
38+
"paragonie/random_compat": "^2.0 || ^1.0",
3839
"ext-intl": "*",
3940
"ext-mbstring": "*"
4041
},
4142
"require-dev": {
4243
"guzzlehttp/guzzle": "^6.0",
43-
"phpunit/phpunit": "^6.0 || ^5.7.14",
44+
"phpunit/phpunit": "^6.0 || ^5.7.21",
4445
"phpmd/phpmd": "@stable",
4546
"squizlabs/php_codesniffer": "^2.6",
4647
"sebastian/phpcpd": "@stable",
@@ -76,7 +77,7 @@
7677
},
7778
"extra": {
7879
"branch-alias": {
79-
"dev-develop": "2.0-dev"
80+
"dev-develop": "2.3-dev"
8081
},
8182
"incenteev-parameters": [
8283
{

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": "2.1.0",
3+
"version": "2.2.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",

phpunit.xml.dist

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@
1818
<directory suffix=".php">src</directory>
1919
</whitelist>
2020
</filter>
21-
21+
<listeners>
22+
<listener class="Commercetools\Core\ErrorListener" file="tests/integration/ErrorListener.php">
23+
</listener>
24+
</listeners>
2225
<!--<logging>
2326
<log type="coverage-html" target="build/coverage" title="Commercetools PHP SDK"
2427
charset="UTF-8" yui="true" highlight="true"

phpunit5.xml.dist

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="vendor/autoload.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
6+
verbose="true">
7+
<testsuites>
8+
<testsuite name="unit">
9+
<directory suffix="Test.php">tests/unit</directory>
10+
</testsuite>
11+
<testsuite name="integration">
12+
<directory suffix="Test.php">tests/integration</directory>
13+
</testsuite>
14+
</testsuites>
15+
16+
<filter>
17+
<whitelist addUncoveredFilesFromWhitelist="true">
18+
<directory suffix=".php">src</directory>
19+
</whitelist>
20+
</filter>
21+
<listeners>
22+
<listener class="Commercetools\Core\ErrorListener5" file="tests/integration/ErrorListener5.php">
23+
</listener>
24+
</listeners>
25+
</phpunit>

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 = '2.1.0';
17+
const VERSION = '2.2.0';
1818

1919
/**
2020
* @var AdapterInterface

src/Core/Client.php

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
namespace Commercetools\Core;
88

9+
use Commercetools\Core\Client\Adapter\CorrelationIdAware;
10+
use Commercetools\Core\Client\Adapter\TokenProviderAware;
11+
use Commercetools\Core\Helper\CorrelationIdProvider;
12+
use Commercetools\Core\Client\Adapter\AdapterOptionInterface;
913
use Commercetools\Core\Response\ErrorResponse;
1014
use Psr\Http\Message\RequestInterface;
1115
use Psr\Http\Message\ResponseInterface;
@@ -198,14 +202,27 @@ public function setLogger(LoggerInterface $logger = null)
198202
public function getHttpClient($options = [])
199203
{
200204
if (is_null($this->httpClient)) {
205+
$clientOptions = $this->config->getClientOptions();
206+
if (count($clientOptions)) {
207+
$options = array_merge($clientOptions, $options);
208+
}
201209
$client = parent::getHttpClient($options);
210+
if ($client instanceof TokenProviderAware) {
211+
$client->setOAuthTokenProvider($this->getOauthManager());
212+
}
202213
if ($this->logger instanceof LoggerInterface) {
203214
$client->setLogger(
204215
$this->logger,
205216
$this->getConfig()->getLogLevel(),
206217
$this->getConfig()->getMessageFormatter()
207218
);
208219
}
220+
if ($this->getConfig()->getCorrelationIdProvider() instanceof CorrelationIdProvider
221+
&& $client instanceof CorrelationIdAware
222+
) {
223+
$client->setCorrelationIdProvider($this->getConfig()->getCorrelationIdProvider());
224+
}
225+
$this->httpClient = $client;
209226
}
210227

211228
return $this->httpClient;
@@ -225,19 +242,25 @@ protected function getBaseUrl()
225242
*
226243
* @param ClientRequestInterface $request
227244
* @param array $headers
245+
* @param array $clientOptions
228246
* @return ApiResponseInterface
229247
* @throws ApiException
230248
* @throws InvalidTokenException
231249
*/
232-
public function execute(ClientRequestInterface $request, array $headers = null)
250+
public function execute(ClientRequestInterface $request, array $headers = null, array $clientOptions = [])
233251
{
234252
if ($request instanceof ContextAwareInterface) {
235253
$request->setContextIfNull($this->getConfig()->getContext());
236254
}
237255
$httpRequest = $this->createHttpRequest($request, $headers);
238256

239257
try {
240-
$httpResponse = $this->getHttpClient()->execute($httpRequest);
258+
$client = $this->getHttpClient();
259+
if ($client instanceof AdapterOptionInterface) {
260+
$httpResponse = $client->execute($httpRequest, $clientOptions);
261+
} else {
262+
$httpResponse = $client->execute($httpRequest);
263+
}
241264
$response = $request->buildResponse($httpResponse);
242265
} catch (ApiException $exception) {
243266
if ($exception instanceof InvalidTokenException && !$this->tokenRefreshed) {
@@ -261,15 +284,21 @@ public function execute(ClientRequestInterface $request, array $headers = null)
261284
/**
262285
* Executes an API request asynchronously
263286
* @param ClientRequestInterface $request
287+
* @param array $clientOptions
264288
* @return ApiResponseInterface
265289
*/
266-
public function executeAsync(ClientRequestInterface $request, array $headers = null)
290+
public function executeAsync(ClientRequestInterface $request, array $headers = null, array $clientOptions = [])
267291
{
268292
if ($request instanceof ContextAwareInterface) {
269293
$request->setContextIfNull($this->getConfig()->getContext());
270294
}
271295
$httpRequest = $this->createHttpRequest($request, $headers);
272-
$response = $request->buildResponse($this->getHttpClient()->executeAsync($httpRequest));
296+
$client = $this->getHttpClient();
297+
if ($client instanceof AdapterOptionInterface) {
298+
$response = $request->buildResponse($client->executeAsync($httpRequest, $clientOptions));
299+
} else {
300+
$response = $request->buildResponse($client->executeAsync($httpRequest));
301+
}
273302

274303
$response = $response->then(
275304
function ($httpResponse) use ($httpRequest) {
@@ -288,11 +317,13 @@ function ($httpResponse) use ($httpRequest) {
288317
*/
289318
protected function createHttpRequest(ClientRequestInterface $request, array $headers = null)
290319
{
291-
$token = $this->getOauthManager()->getToken();
292320
$httpRequest = $request->httpRequest();
293-
$httpRequest = $httpRequest
294-
->withHeader('Authorization', 'Bearer ' . $token->getToken())
295-
;
321+
if (!$this->getHttpClient() instanceof TokenProviderAware) {
322+
$token = $this->getOauthManager()->getToken();
323+
$httpRequest = $httpRequest
324+
->withHeader('Authorization', 'Bearer ' . $token->getToken())
325+
;
326+
}
296327
if (is_array($headers)) {
297328
foreach ($headers as $headerName => $headerValues) {
298329
$httpRequest = $httpRequest
@@ -307,13 +338,19 @@ protected function createHttpRequest(ClientRequestInterface $request, array $hea
307338
/**
308339
* Executes API requests in batch
309340
* @param array $headers
341+
* @param array $clientOptions
310342
* @return ApiResponseInterface[]
311343
* @throws ApiException
312344
*/
313-
public function executeBatch(array $headers = null)
345+
public function executeBatch(array $headers = null, array $clientOptions = [])
314346
{
315347
$requests = $this->getBatchHttpRequests($headers);
316-
$httpResponses = $this->getHttpClient()->executeBatch($requests);
348+
$client = $this->getHttpClient();
349+
if ($client instanceof AdapterOptionInterface) {
350+
$httpResponses = $client->executeBatch($requests, $clientOptions);
351+
} else {
352+
$httpResponses = $client->executeBatch($requests);
353+
}
317354

318355
$responses = [];
319356
foreach ($httpResponses as $key => $httpResponse) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
*/
5+
6+
namespace Commercetools\Core\Client\Adapter;
7+
8+
use Psr\Http\Message\RequestInterface;
9+
use Psr\Http\Message\ResponseInterface;
10+
11+
interface AdapterOptionInterface extends AdapterInterface
12+
{
13+
/**
14+
* @param RequestInterface $request
15+
* @param array $clientOptions
16+
* @return ResponseInterface
17+
*/
18+
public function execute(RequestInterface $request, array $clientOptions = []);
19+
20+
/**
21+
* @param RequestInterface[] $requests
22+
* @param array $clientOptions
23+
* @return ResponseInterface[]
24+
*/
25+
public function executeBatch(array $requests, array $clientOptions = []);
26+
27+
/**
28+
* @param RequestInterface $request
29+
* @param array $clientOptions
30+
* @return AdapterPromiseInterface
31+
*/
32+
public function executeAsync(RequestInterface $request, array $clientOptions = []);
33+
}

0 commit comments

Comments
 (0)