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

Commit 5d5b152

Browse files
author
Jens Schulze
committed
Merge branch 'release/v1.2.0'
2 parents 5f432b4 + 07f2348 commit 5d5b152

File tree

483 files changed

+4094
-597
lines changed

Some content is hidden

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

483 files changed

+4094
-597
lines changed

.travis.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ php:
99
matrix:
1010
allow_failures:
1111
- php: hhvm
12-
- php: 7.0
1312

1413
services:
1514
- redis-server
@@ -19,20 +18,21 @@ cache:
1918
- vendor
2019

2120
before_script:
21+
- PHP=$TRAVIS_PHP_VERSION
2222
- composer config -g github-oauth.github.com $GITHUB_OAUTH_TOKEN
23-
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] && [ `php-config --vernum` -lt 70000 ] ; then echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; fi"
24-
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] && [ `php-config --vernum` -ge 50400 ] && [ `php-config --vernum` -lt 70000 ]; then printf "yes\n" | pecl install -f apcu-4.0.10 ; fi"
25-
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] && [ `php-config --vernum` -ge 70000 ] ; then printf "yes\n" | pecl install -f apcu-5.1.3 ; fi"
26-
- sh -c "if [ $TRAVIS_PHP_VERSION != 'hhvm' ] ; then phpenv config-add ./tests/apc.ini; fi"
27-
- if [ $TRAVIS_PHP_VERSION == '5.4' ] ; then ./set_guzzle5.sh; fi
23+
- sh -c "if [ $PHP != 'hhvm' ] && [ `php-config --vernum` -lt 70000 ] ; then echo 'extension = redis.so' >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini ; fi"
24+
- sh -c "if [ $PHP != 'hhvm' ] && [ `php-config --vernum` -ge 50400 ] && [ `php-config --vernum` -lt 70000 ]; then printf "yes\n" | pecl install -f apcu-4.0.10 ; fi"
25+
- sh -c "if [ $PHP != 'hhvm' ] && [ `php-config --vernum` -ge 70000 ] ; then printf "yes\n" | pecl install -f apcu-5.1.3 ; fi"
26+
- sh -c "if [ $PHP != 'hhvm' ] ; then phpenv config-add ./tests/apc.ini; fi"
27+
- if [ $PHP == '5.4' ] ; then ./set_guzzle5.sh; fi
2828
- composer global require hirak/prestissimo
2929
- composer self-update
3030
- composer install -o --prefer-dist
3131

3232
script:
3333
- ant phpcs-ci
3434
- phpunit --testsuite=unit
35-
- if [ $TRAVIS_PHP_VERSION == '5.6' ] ; then phpunit --testsuite=integration; fi
35+
- if [ $PHP == '7.0' ] ; then phpunit --testsuite=integration; fi
3636
- ant behat
3737

3838
after_success:

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,25 @@
1+
<a name="1.2.0"></a>
2+
# [1.2.0](https://github.com/sphereio/commercetools-php-sdk/compare/v1.1.1...v1.2.0) (2016-06-30)
3+
4+
5+
### Bug Fixes
6+
7+
* **Client:** fix format of UserAgent header ([bc37b2f](https://github.com/sphereio/commercetools-php-sdk/commit/bc37b2f))
8+
9+
10+
### Features
11+
12+
* **Cart:** add updateProductData flag to cart recalculate action ([827a392](https://github.com/sphereio/commercetools-php-sdk/commit/827a392)), closes [#220](https://github.com/sphereio/commercetools-php-sdk/issues/220)
13+
* **Cart:** support anonymous checkout for me endpoint ([a89f38c](https://github.com/sphereio/commercetools-php-sdk/commit/a89f38c)), closes [#221](https://github.com/sphereio/commercetools-php-sdk/issues/221)
14+
* **MeEndpoint:** add get active cart request ([e61d29d](https://github.com/sphereio/commercetools-php-sdk/commit/e61d29d)), closes [#224](https://github.com/sphereio/commercetools-php-sdk/issues/224)
15+
* **MyProfile:** support customer profile on me endpoint ([3cc0f73](https://github.com/sphereio/commercetools-php-sdk/commit/3cc0f73)), closes [#223](https://github.com/sphereio/commercetools-php-sdk/issues/223)
16+
* **Orders:** add support for orders at me endpoint ([e776230](https://github.com/sphereio/commercetools-php-sdk/commit/e776230)), closes [#222](https://github.com/sphereio/commercetools-php-sdk/issues/222)
17+
* **Product:** add image upload request ([e8985bd](https://github.com/sphereio/commercetools-php-sdk/commit/e8985bd)), closes [#146](https://github.com/sphereio/commercetools-php-sdk/issues/146)
18+
* **Product:** support product price selection ([02026a7](https://github.com/sphereio/commercetools-php-sdk/commit/02026a7)),([ebac224](https://github.com/sphereio/commercetools-php-sdk/commit/ebac224)), closes [#225](https://github.com/sphereio/commercetools-php-sdk/issues/225)
19+
* **ProductSearch:** add fuzzy level support ([617a4ea](https://github.com/sphereio/commercetools-php-sdk/commit/617a4ea)), closes [#217](https://github.com/sphereio/commercetools-php-sdk/issues/217)
20+
21+
22+
123
<a name="1.1.1"></a>
224
## [1.1.1](https://github.com/sphereio/commercetools-php-sdk/compare/v1.1.0...v1.1.1) (2016-06-07)
325

src/AbstractHttpClient.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*/
1515
abstract class AbstractHttpClient
1616
{
17-
const VERSION = '1.1.1';
17+
const VERSION = '1.2.0';
1818

1919
/**
2020
* @var AdapterInterface
@@ -112,11 +112,10 @@ abstract protected function getBaseUrl();
112112
protected function getUserAgent()
113113
{
114114
if (is_null($this->userAgent)) {
115-
$agent = 'commercetools-php-sdk ' . static::VERSION;
116-
if (extension_loaded('curl')) {
117-
$agent .= ' curl/' . curl_version()['version'];
115+
$agent = 'commercetools-php-sdk/' . static::VERSION . ' PHP/' . PHP_VERSION;
116+
if (extension_loaded('curl') && function_exists('curl_version')) {
117+
$agent .= ' curl/' . \curl_version()['version'];
118118
}
119-
$agent .= ' PHP/' . PHP_VERSION;
120119
$this->userAgent = $agent;
121120
}
122121

src/Client/FileRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/**
1010
* @package Commercetools\Core\Http
1111
* @internal
12+
* @deprecated replaced by FileUploadRequest. will be removed with v2.0
1213
*/
1314
class FileRequest extends HttpRequest
1415
{

src/Client/FileUploadRequest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* @author @jayS-de <[email protected]>
4+
* @created: 23.01.15, 16:07
5+
*/
6+
7+
namespace Commercetools\Core\Client;
8+
9+
use Psr\Http\Message\UploadedFileInterface;
10+
11+
/**
12+
* @package Commercetools\Core\Http
13+
* @internal
14+
*/
15+
class FileUploadRequest extends HttpRequest
16+
{
17+
public function __construct($path, UploadedFileInterface $file)
18+
{
19+
parent::__construct('POST', $path, $file->getStream(), $file->getClientMediaType());
20+
}
21+
}

src/Client/OAuth/Manager.php

Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Manager extends AbstractHttpClient
2424
{
2525
const TOKEN_CACHE_KEY = 'commercetools_io_access_token';
2626

27+
const ANONYMOUS_ID = 'anonymous_id';
2728
const REFRESH_TOKEN = 'refresh_token';
2829
const ACCESS_TOKEN = 'access_token';
2930
const EXPIRES_IN = 'expires_in';
@@ -108,38 +109,51 @@ public function refreshToken()
108109
$grantType = $this->getConfig()->getGrantType();
109110
$data = [Config::SCOPE => $scope, Config::GRANT_TYPE => $grantType];
110111

111-
if ($grantType === Config::GRANT_TYPE_PASSWORD) {
112-
$user = $this->getConfig()->getUsername();
113-
$password = $this->getConfig()->getPassword();
114-
$data[Config::USER_NAME] = $user;
115-
$data[Config::PASSWORD] = $password;
116-
} elseif ($grantType === Config::GRANT_TYPE_REFRESH) {
117-
$refreshToken = $this->getConfig()->getRefreshToken();
118-
$data[Config::REFRESH_TOKEN] = $refreshToken;
112+
switch ($grantType) {
113+
case Config::GRANT_TYPE_PASSWORD:
114+
$user = $this->getConfig()->getUsername();
115+
$password = $this->getConfig()->getPassword();
116+
$data[Config::USER_NAME] = $user;
117+
$data[Config::PASSWORD] = $password;
118+
break;
119+
case Config::GRANT_TYPE_REFRESH:
120+
$refreshToken = $this->getConfig()->getRefreshToken();
121+
$data[Config::REFRESH_TOKEN] = $refreshToken;
122+
break;
123+
case Config::GRANT_TYPE_ANONYMOUS:
124+
$data[Config::GRANT_TYPE] = Config::GRANT_TYPE_CLIENT;
125+
$anonymousId = $this->getConfig()->getAnonymousId();
126+
if (!empty($anonymousId)) {
127+
$data[Config::ANONYMOUS_ID] = $anonymousId;
128+
}
119129
}
120-
121-
$token = $this->getBearerToken($data);
122130

123-
if ($grantType === Config::GRANT_TYPE_PASSWORD) {
124-
$this->getConfig()->setGrantType(Config::GRANT_TYPE_REFRESH);
125-
$this->getConfig()->setRefreshToken($token->getRefreshToken());
126-
}
131+
$token = $this->getBearerToken($data);
127132

128133
// ensure token to be invalidated in cache before TTL
129134
$ttl = max(1, floor($token->getTtl()/2));
135+
130136
$this->cache($token, $ttl);
131137

138+
if ($grantType === Config::GRANT_TYPE_PASSWORD || $grantType == Config::GRANT_TYPE_ANONYMOUS) {
139+
$this->getConfig()->setRefreshToken($token->getRefreshToken());
140+
$this->cache($token, $ttl, $this->getCacheKey(Config::GRANT_TYPE_REFRESH));
141+
}
142+
132143
return $token;
133144
}
134145

135-
protected function cache(Token $token, $ttl)
146+
protected function cache(Token $token, $ttl, $cacheKey = null)
136147
{
148+
if (is_null($cacheKey)) {
149+
$cacheKey = $this->getCacheKey();
150+
}
137151
$cache = $this->getCacheAdapter();
138152
if ($cache instanceof CacheAdapterInterface) {
139-
$cache->store($this->getCacheKey(), $token->getToken(), (int)$ttl);
153+
$cache->store($cacheKey, $token->getToken(), (int)$ttl);
140154
}
141155
if ($cache instanceof CacheItemPoolInterface) {
142-
$item = new CacheItem($this->getCacheKey(), true, $token->getToken());
156+
$item = new CacheItem($cacheKey, true, $token->getToken());
143157
$item->expiresAfter((int)$ttl);
144158
$cache->save($item);
145159
}
@@ -164,18 +178,29 @@ protected function getCacheToken()
164178
/**
165179
* @return string
166180
*/
167-
protected function getCacheKey()
181+
protected function getCacheKey($grantType = null)
168182
{
169183
$scope = $this->getConfig()->getScope();
170-
$grantType = $this->getConfig()->getGrantType();
184+
if (is_null($grantType)) {
185+
$grantType = $this->getConfig()->getGrantType();
186+
}
171187
$cacheScope = $scope . '-' . $grantType;
172188

173-
if ($grantType === Config::GRANT_TYPE_PASSWORD) {
174-
$user = $this->getConfig()->getUsername();
175-
$cacheScope .= '-' . $user;
176-
} elseif ($grantType === Config::GRANT_TYPE_REFRESH) {
177-
$token = $this->getConfig()->getRefreshToken();
178-
$cacheScope .= '-' . $token;
189+
switch ($grantType) {
190+
case Config::GRANT_TYPE_PASSWORD:
191+
$user = base64_encode($this->getConfig()->getUsername());
192+
$cacheScope .= '-' . $user;
193+
break;
194+
case Config::GRANT_TYPE_REFRESH:
195+
$token = $this->getConfig()->getRefreshToken();
196+
$cacheScope .= '-' . $token;
197+
break;
198+
case Config::GRANT_TYPE_ANONYMOUS:
199+
$anonymousId = $this->getConfig()->getAnonymousId();
200+
if (!empty($anonymousId)) {
201+
$cacheScope .= '-' . $anonymousId;
202+
}
203+
break;
179204
}
180205

181206
if (!isset($this->cacheKeys[$cacheScope])) {

src/Config.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,13 @@ class Config implements ContextAwareInterface
6565
const USER_NAME = 'username';
6666
const PASSWORD = 'password';
6767
const REFRESH_TOKEN = 'refresh_token';
68+
const ANONYMOUS_ID = 'anonymous_id';
6869
const GRANT_TYPE = 'grant_type';
6970

7071
const GRANT_TYPE_CLIENT = 'client_credentials';
7172
const GRANT_TYPE_PASSWORD = 'password';
7273
const GRANT_TYPE_REFRESH = 'refresh_token';
74+
const GRANT_TYPE_ANONYMOUS = 'anonymous_token';
7375

7476
/**
7577
* @var string
@@ -132,6 +134,11 @@ class Config implements ContextAwareInterface
132134
*/
133135
protected $refreshToken;
134136

137+
/**
138+
* @var string
139+
*/
140+
protected $anonymousId;
141+
135142
/**
136143
* @var string
137144
*/
@@ -275,6 +282,8 @@ public function setScope($scope)
275282
public function getOauthUrl()
276283
{
277284
switch ($this->getGrantType()) {
285+
case static::GRANT_TYPE_ANONYMOUS:
286+
return $this->oauthUrl . '/oauth/' . $this->getProject() . '/anonymous/token';
278287
case static::GRANT_TYPE_PASSWORD:
279288
case static::GRANT_TYPE_REFRESH:
280289
return $this->oauthUrl . '/oauth/' . $this->getProject() . '/customers/token';
@@ -493,6 +502,25 @@ public function setRefreshToken($refreshToken)
493502
return $this;
494503
}
495504

505+
/**
506+
* @return string
507+
*/
508+
public function getAnonymousId()
509+
{
510+
return $this->anonymousId;
511+
}
512+
513+
/**
514+
* @param string $anonymousId
515+
* @return string
516+
*/
517+
public function setAnonymousId($anonymousId)
518+
{
519+
$this->anonymousId = $anonymousId;
520+
521+
return $this;
522+
}
523+
496524
/**
497525
* @return string
498526
*/

src/Error/DuplicateFieldError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @method DuplicateFieldError setMessage(string $message = null)
1515
* @method string getField()
1616
* @method DuplicateFieldError setField(string $field = null)
17-
* @method getDuplicateValue()
17+
* @method mixed getDuplicateValue()
1818
* @method DuplicateFieldError setDuplicateValue($duplicateValue = null)
1919
*/
2020
class DuplicateFieldError extends ApiError

src/Error/InvalidFieldError.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @method InvalidFieldError setMessage(string $message = null)
1515
* @method string getField()
1616
* @method InvalidFieldError setField(string $field = null)
17-
* @method getInvalidValue()
17+
* @method mixed getInvalidValue()
1818
* @method InvalidFieldError setInvalidValue($invalidValue = null)
1919
* @method array getAllowedValues()
2020
* @method InvalidFieldError setAllowedValues(array $allowedValues = null)

src/Helper/Annotate/ClassAnnotator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,11 @@ protected function reflectFields()
4545
$getReturnType = $field[JsonObject::DECORATOR];
4646
$this->class->addUse($field[JsonObject::DECORATOR]);
4747
} else {
48-
$getReturnType = $fieldType;
48+
if (empty($fieldType)) {
49+
$getReturnType = 'mixed';
50+
} else {
51+
$getReturnType = $fieldType;
52+
}
4953
}
5054
$getReturnTypeParts = explode('\\', trim($getReturnType, '\\'));
5155
if (!$this->isPrimitive($fieldType) && count($getReturnTypeParts) > 1) {

0 commit comments

Comments
 (0)