1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright © 2016-present Spryker Systems GmbH. All rights reserved. |
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace SprykerEco\Service\AkeneoPim\Dependencies\External\Api\Adapter\HttpClient; |
9
|
|
|
|
10
|
|
|
use GuzzleHttp\Client as GuzzleHttpClient; |
11
|
|
|
use GuzzleHttp\ClientInterface; |
12
|
|
|
use GuzzleHttp\HandlerStack; |
13
|
|
|
use GuzzleHttp\Middleware; |
14
|
|
|
use GuzzleHttp\Utils; |
15
|
|
|
use Http\Client\HttpClient; |
16
|
|
|
use Http\Promise\Promise as HttpPromise; |
17
|
|
|
use Psr\Http\Message\RequestInterface; |
18
|
|
|
use Psr\Http\Message\ResponseInterface; |
19
|
|
|
use function GuzzleHttp\choose_handler; |
20
|
|
|
|
21
|
|
|
class Client implements HttpClient |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
/** |
24
|
|
|
* @var \GuzzleHttp\ClientInterface |
25
|
|
|
*/ |
26
|
|
|
protected $client; |
27
|
|
|
|
28
|
|
|
public function __construct() |
29
|
|
|
{ |
30
|
|
|
$this->client = $this->buildClient(); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param \Psr\Http\Message\RequestInterface $request |
35
|
|
|
* |
36
|
|
|
* @return \Psr\Http\Message\ResponseInterface |
37
|
|
|
*/ |
38
|
|
|
public function sendRequest(RequestInterface $request): ResponseInterface |
39
|
|
|
{ |
40
|
|
|
return $this->sendAsyncRequest($request)->wait(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @param \Psr\Http\Message\RequestInterface $request |
45
|
|
|
* |
46
|
|
|
* @return \Http\Promise\Promise |
47
|
|
|
*/ |
48
|
|
|
protected function sendAsyncRequest(RequestInterface $request): HttpPromise |
49
|
|
|
{ |
50
|
|
|
$promise = $this->client->sendAsync($request); |
51
|
|
|
|
52
|
|
|
return new Promise($promise, $request); |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @return \GuzzleHttp\ClientInterface |
57
|
|
|
*/ |
58
|
|
|
protected function buildClient(): ClientInterface |
59
|
|
|
{ |
60
|
|
|
$handlerStack = $this->createHandlerStack(); |
61
|
|
|
$handlerStack->push(Middleware::prepareBody(), 'prepare_body'); |
62
|
|
|
|
63
|
|
|
return new GuzzleHttpClient(['handler' => $handlerStack]); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @return \GuzzleHttp\HandlerStack |
68
|
|
|
*/ |
69
|
|
|
protected function createHandlerStack(): HandlerStack |
70
|
|
|
{ |
71
|
|
|
if (method_exists(Utils::class, 'chooseHandler')) { |
72
|
|
|
return new HandlerStack(Utils::chooseHandler()); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
return new HandlerStack(choose_handler()); |
|
|
|
|
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This interface has been deprecated. The supplier of the interface has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the interface will be removed and what other interface to use instead.