1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Commercetools\Core\Client; |
4
|
|
|
|
5
|
|
|
use Commercetools\Core\Request\ClientRequestInterface; |
6
|
|
|
use GuzzleHttp\Client; |
7
|
|
|
use GuzzleHttp\Exception\GuzzleException; |
8
|
|
|
use GuzzleHttp\Promise\PromiseInterface; |
9
|
|
|
use Psr\Http\Message\ResponseInterface; |
10
|
|
|
|
11
|
|
|
class HttpClient extends Client |
12
|
|
|
{ |
13
|
|
|
/** |
14
|
|
|
* @param ClientRequestInterface $request |
15
|
|
|
* @param array|null $headers |
16
|
|
|
* @param array $options |
17
|
|
|
* @return mixed|ResponseInterface |
18
|
|
|
* @throws GuzzleException |
19
|
|
|
*/ |
20
|
1 |
|
public function execute(ClientRequestInterface $request, array $headers = null, array $options = []) |
21
|
|
|
{ |
22
|
1 |
|
$httpRequest = $request->httpRequest(); |
23
|
1 |
|
if (is_array($headers)) { |
24
|
|
|
foreach ($headers as $headerName => $headerValues) { |
25
|
|
|
$httpRequest = $httpRequest |
26
|
|
|
->withAddedHeader($headerName, $headerValues) |
27
|
|
|
; |
28
|
|
|
} |
29
|
|
|
} |
30
|
1 |
|
return parent::send($httpRequest, $options); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param ClientRequestInterface $request |
35
|
|
|
* @param array|null $headers |
36
|
|
|
* @param array $options |
37
|
|
|
* @return PromiseInterface |
38
|
|
|
*/ |
39
|
1 |
|
public function executeAsync(ClientRequestInterface $request, array $headers = null, array $options = []) |
40
|
|
|
{ |
41
|
1 |
|
$httpRequest = $request->httpRequest(); |
42
|
1 |
|
if (is_array($headers)) { |
43
|
|
|
foreach ($headers as $headerName => $headerValues) { |
44
|
|
|
$httpRequest = $httpRequest |
45
|
|
|
->withAddedHeader($headerName, $headerValues) |
46
|
|
|
; |
47
|
|
|
} |
48
|
|
|
} |
49
|
1 |
|
return parent::sendAsync($httpRequest, $options); |
50
|
|
|
} |
51
|
|
|
} |
52
|
|
|
|