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

Commit 9ca58c8

Browse files
author
Jens Schulze
authored
feat(Extension): support API extensions
Closes #365
1 parent b6cb2c6 commit 9ca58c8

File tree

83 files changed

+3173
-905
lines changed

Some content is hidden

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

83 files changed

+3173
-905
lines changed

bin/ctp-tlscheck.php

Lines changed: 45 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@
33

44
class Tls12Checker
55
{
6-
const API_URI = 'api.escemo.com';
6+
const API_URI = 'api-tls12.commercetools.com';
7+
8+
const URIS = [
9+
'auth-tls12.commercetools.com',
10+
'api-tls12.commercetools.com',
11+
'auth-tls12.commercetools.co',
12+
'api-tls12.commercetools.co',
13+
'api.sphere.io',
14+
'api.commercetools.co',
15+
];
716

817
public function allowedCiphers()
918
{
@@ -59,12 +68,14 @@ private function checkCiphers()
5968
}
6069

6170
/**
62-
* @throws \Exception
71+
* @param string $apiUri
72+
* @param string $cipher
73+
* @throws Exception
6374
*/
64-
private function checkApiConnection($cipher = null)
75+
private function checkApiConnection($apiUri = self::API_URI, $cipher = null)
6576
{
6677
$ch = curl_init();
67-
curl_setopt($ch, CURLOPT_URL, 'https://' . self::API_URI);
78+
curl_setopt($ch, CURLOPT_URL, 'https://' . $apiUri);
6879
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
6980
if (!is_null($cipher)) {
7081
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, $cipher);
@@ -102,7 +113,9 @@ public function check()
102113
echo "Checking TLS 1.2 connection ... ";
103114
try {
104115
$this->checkCiphers();
105-
$this->checkApiConnection();
116+
foreach (self::URIS as $uri) {
117+
$this->checkApiConnection($uri);
118+
}
106119
} catch (\Exception $exception) {
107120
echo "\033[31mFailed\033[0m" . PHP_EOL;
108121
echo $exception->getMessage() . PHP_EOL;
@@ -114,33 +127,33 @@ public function check()
114127
return 0;
115128
}
116129

117-
private function availableCiphers()
118-
{
119-
$localCiphers = explode(' ', exec('openssl ciphers \'ALL:eNULL\' | tr \':\' \' \''));
120-
$allowedCiphers = [];
121-
foreach ($localCiphers as $localCipher) {
122-
exec('echo -n | openssl s_client -connect ' . self::API_URI . ':443 -cipher ' . $localCipher . ' -tls1_2 2>&1', $dummy, $status);
123-
if ($status === 0) {
124-
$allowedCiphers[] = $localCipher;
125-
}
126-
}
127-
128-
return $allowedCiphers;
129-
}
130-
131-
private function checkAvailableCiphers()
132-
{
133-
$availableCiphers = $this->availableCiphers();
134-
foreach ($availableCiphers as $cipher) {
135-
echo 'Testing ' . $cipher . '...';
136-
try {
137-
$this->checkApiConnection($cipher);
138-
echo "\033[32mOK\033[0m" . PHP_EOL;
139-
} catch (\Exception $exception) {
140-
echo "\033[31mFailed\033[0m" . PHP_EOL;
141-
}
142-
}
143-
}
130+
// private function availableCiphers()
131+
// {
132+
// $localCiphers = explode(' ', exec('openssl ciphers \'ALL:eNULL\' | tr \':\' \' \''));
133+
// $allowedCiphers = [];
134+
// foreach ($localCiphers as $localCipher) {
135+
// exec('echo -n | openssl s_client -connect ' . self::API_URI . ':443 -cipher ' . $localCipher . ' -tls1_2 2>&1', $dummy, $status);
136+
// if ($status === 0) {
137+
// $allowedCiphers[] = $localCipher;
138+
// }
139+
// }
140+
//
141+
// return $allowedCiphers;
142+
// }
143+
//
144+
// private function checkAvailableCiphers()
145+
// {
146+
// $availableCiphers = $this->availableCiphers();
147+
// foreach ($availableCiphers as $cipher) {
148+
// echo 'Testing ' . $cipher . '...';
149+
// try {
150+
// $this->checkApiConnection(self::API_URI, $cipher);
151+
// echo "\033[32mOK\033[0m" . PHP_EOL;
152+
// } catch (\Exception $exception) {
153+
// echo "\033[31mFailed\033[0m" . PHP_EOL;
154+
// }
155+
// }
156+
// }
144157
}
145158

146159
$checker = new Tls12Checker();

build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@
6464
<exec executable="${toolsdir}phpcs${execPostfix}" failonerror="true">
6565
<arg value="--standard=PSR2" />
6666
<arg value="--extensions=php" />
67-
<arg value="--ignore=autoload.php" />
67+
<arg value="--ignore=autoload.php,src/Core/Builder" />
6868
<arg path="${basedir}/src" />
6969
<arg path="${basedir}/tests" />
7070
</exec>
@@ -76,7 +76,7 @@
7676
<exec executable="${toolsdir}phpcs${execPostfix}" failonerror="true">
7777
<arg value="--standard=PSR2" />
7878
<arg value="--extensions=php" />
79-
<arg value="--ignore=autoload.php" />
79+
<arg value="--ignore=autoload.php,src/Core/Builder" />
8080
<arg path="${basedir}/src" />
8181
</exec>
8282
</target>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"require": {
3131
"php": ">=5.6",
3232
"psr/log": "^1.0",
33-
"guzzlehttp/guzzle": "^6.0 || ^5.3.1",
33+
"guzzlehttp/guzzle": "^6.0 || ^5.3.3",
3434
"guzzlehttp/psr7": "^1.1",
3535
"psr/cache": "^1.0",
3636
"psr/simple-cache": "^1.0",

set_guzzle5.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/bin/bash
22
SRC='"guzzlehttp/guzzle": "^6.0"'
3-
DST='"guzzlehttp/guzzle": "^5.3.1", "react/promise": "^2.2.0"'
3+
DST='"guzzlehttp/guzzle": "^5.3.3", "react/promise": "^2.2.0"'
44
sed -ibak -e "s|$SRC|$DST|g" composer.json
Lines changed: 40 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,78 @@
11
<?php
2-
/**
3-
* @author @jenschude <[email protected]>
4-
*/
5-
2+
// phpcs:disable Generic.Files.LineLength
63
namespace Commercetools\Core\Builder\Request;
74

8-
use Commercetools\Core\Model\CartDiscount\CartDiscount;
9-
use Commercetools\Core\Model\CartDiscount\CartDiscountDraft;
105
use Commercetools\Core\Request\CartDiscounts\CartDiscountByIdGetRequest;
116
use Commercetools\Core\Request\CartDiscounts\CartDiscountCreateRequest;
7+
use Commercetools\Core\Model\CartDiscount\CartDiscountDraft;
128
use Commercetools\Core\Request\CartDiscounts\CartDiscountDeleteRequest;
9+
use Commercetools\Core\Model\CartDiscount\CartDiscount;
1310
use Commercetools\Core\Request\CartDiscounts\CartDiscountQueryRequest;
1411
use Commercetools\Core\Request\CartDiscounts\CartDiscountUpdateRequest;
1512

1613
class CartDiscountRequestBuilder
1714
{
18-
/**
19-
* @return CartDiscountQueryRequest
20-
*/
21-
public function query()
22-
{
23-
return CartDiscountQueryRequest::of();
24-
}
2515

2616
/**
27-
* @param CartDiscount $cartDiscount
28-
* @return CartDiscountUpdateRequest
17+
* @link https://docs.commercetools.com/http-api-projects-cartDiscounts.html#get-cartdiscount-by-id
18+
* @param string $id
19+
* @return CartDiscountByIdGetRequest
2920
*/
30-
public function update(CartDiscount $cartDiscount)
21+
public function getById($id)
3122
{
32-
return CartDiscountUpdateRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
23+
$request = CartDiscountByIdGetRequest::ofId($id);
24+
return $request;
3325
}
3426

3527
/**
28+
* @link https://docs.commercetools.com/http-api-projects-cartDiscounts.html#create-a-cartdiscount
3629
* @param CartDiscountDraft $cartDiscountDraft
3730
* @return CartDiscountCreateRequest
3831
*/
3932
public function create(CartDiscountDraft $cartDiscountDraft)
4033
{
41-
return CartDiscountCreateRequest::ofDraft($cartDiscountDraft);
34+
$request = CartDiscountCreateRequest::ofDraft($cartDiscountDraft);
35+
return $request;
4236
}
4337

4438
/**
39+
* @link https://docs.commercetools.com/http-api-projects-cartDiscounts.html#delete-cartdiscount
4540
* @param CartDiscount $cartDiscount
4641
* @return CartDiscountDeleteRequest
4742
*/
4843
public function delete(CartDiscount $cartDiscount)
4944
{
50-
return CartDiscountDeleteRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
45+
$request = CartDiscountDeleteRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
46+
return $request;
5147
}
5248

5349
/**
54-
* @param string $id
55-
* @return CartDiscountByIdGetRequest
50+
* @link https://docs.commercetools.com/http-api-projects-cartDiscounts.html#query-cartdiscounts
51+
*
52+
* @return CartDiscountQueryRequest
5653
*/
57-
public function getById($id)
54+
public function query()
55+
{
56+
$request = CartDiscountQueryRequest::of();
57+
return $request;
58+
}
59+
60+
/**
61+
* @link https://docs.commercetools.com/http-api-projects-cartDiscounts.html#update-cartdiscount
62+
* @param CartDiscount $cartDiscount
63+
* @return CartDiscountUpdateRequest
64+
*/
65+
public function update(CartDiscount $cartDiscount)
66+
{
67+
$request = CartDiscountUpdateRequest::ofIdAndVersion($cartDiscount->getId(), $cartDiscount->getVersion());
68+
return $request;
69+
}
70+
71+
/**
72+
* @return CartDiscountRequestBuilder
73+
*/
74+
public function of()
5875
{
59-
return CartDiscountByIdGetRequest::ofId($id);
76+
return new self();
6077
}
6178
}
Lines changed: 50 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,102 @@
11
<?php
2-
/**
3-
* @author @jenschude <[email protected]>
4-
*/
5-
2+
// phpcs:disable Generic.Files.LineLength
63
namespace Commercetools\Core\Builder\Request;
74

8-
use Commercetools\Core\Model\Cart\Cart;
9-
use Commercetools\Core\Model\Cart\CartDraft;
105
use Commercetools\Core\Request\Carts\CartByCustomerIdGetRequest;
116
use Commercetools\Core\Request\Carts\CartByIdGetRequest;
127
use Commercetools\Core\Request\Carts\CartCreateRequest;
8+
use Commercetools\Core\Model\Cart\CartDraft;
139
use Commercetools\Core\Request\Carts\CartDeleteRequest;
10+
use Commercetools\Core\Model\Cart\Cart;
1411
use Commercetools\Core\Request\Carts\CartQueryRequest;
1512
use Commercetools\Core\Request\Carts\CartReplicateRequest;
1613
use Commercetools\Core\Request\Carts\CartUpdateRequest;
1714

1815
class CartRequestBuilder
1916
{
17+
2018
/**
21-
* @return CartQueryRequest
19+
* @link https://docs.commercetools.com/http-api-projects-carts.html#get-cart-by-customer-id
20+
* @param string $customerId
21+
* @return CartByCustomerIdGetRequest
2222
*/
23-
public function query()
23+
public function getByCustomerId($customerId)
2424
{
25-
return CartQueryRequest::of();
25+
$request = CartByCustomerIdGetRequest::ofCustomerId($customerId);
26+
return $request;
2627
}
2728

2829
/**
29-
* @param Cart $cart
30-
* @return CartUpdateRequest
30+
* @link https://docs.commercetools.com/http-api-projects-carts.html#get-cart-by-id
31+
* @param string $id
32+
* @return CartByIdGetRequest
3133
*/
32-
public function update(Cart $cart)
34+
public function getById($id)
3335
{
34-
return CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
36+
$request = CartByIdGetRequest::ofId($id);
37+
return $request;
3538
}
3639

3740
/**
41+
* @link https://docs.commercetools.com/http-api-projects-carts.html#create-cart
3842
* @param CartDraft $cartDraft
3943
* @return CartCreateRequest
4044
*/
4145
public function create(CartDraft $cartDraft)
4246
{
43-
return CartCreateRequest::ofDraft($cartDraft);
47+
$request = CartCreateRequest::ofDraft($cartDraft);
48+
return $request;
4449
}
4550

4651
/**
52+
* @link https://docs.commercetools.com/http-api-projects-carts.html#delete-cart
4753
* @param Cart $cart
4854
* @return CartDeleteRequest
4955
*/
5056
public function delete(Cart $cart)
5157
{
52-
return CartDeleteRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
58+
$request = CartDeleteRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
59+
return $request;
5360
}
5461

5562
/**
56-
* @param string $id
57-
* @return CartByIdGetRequest
63+
* @link https://docs.commercetools.com/http-api-projects-carts.html#query-carts
64+
*
65+
* @return CartQueryRequest
5866
*/
59-
public function getById($id)
67+
public function query()
6068
{
61-
return CartByIdGetRequest::ofId($id);
69+
$request = CartQueryRequest::of();
70+
return $request;
6271
}
6372

6473
/**
65-
* @param string $customerId
66-
* @return CartByCustomerIdGetRequest
74+
* @link https://docs.commercetools.com/http-api-projects-carts.html#replicate-existing-cart-or-order-to-a-new-cart
75+
* @param string $cartId
76+
* @return CartReplicateRequest
6777
*/
68-
public function getByCustomerId($customerId)
78+
public function replicate($cartId)
6979
{
70-
return CartByCustomerIdGetRequest::ofCustomerId($customerId);
80+
$request = CartReplicateRequest::ofCartId($cartId);
81+
return $request;
7182
}
7283

73-
public function replicate($cartId)
84+
/**
85+
* @link https://docs.commercetools.com/http-api-projects-carts.html#update-cart
86+
* @param Cart $cart
87+
* @return CartUpdateRequest
88+
*/
89+
public function update(Cart $cart)
90+
{
91+
$request = CartUpdateRequest::ofIdAndVersion($cart->getId(), $cart->getVersion());
92+
return $request;
93+
}
94+
95+
/**
96+
* @return CartRequestBuilder
97+
*/
98+
public function of()
7499
{
75-
return CartReplicateRequest::ofCartId($cartId);
100+
return new self();
76101
}
77102
}

0 commit comments

Comments
 (0)