1 | <?php |
||
21 | final class Client implements HttpClient, HttpAsyncClient |
||
22 | { |
||
23 | /** |
||
24 | * @var ClientInterface |
||
25 | */ |
||
26 | private $client; |
||
27 | |||
28 | /** |
||
29 | * If you pass a Guzzle instance as $client, make sure to configure Guzzle to not |
||
30 | * throw exceptions on HTTP error status codes, or this adapter will violate PSR-18. |
||
31 | * See also self::buildClient at the bottom of this class. |
||
32 | */ |
||
33 | 363 | public function __construct(?ClientInterface $client = null) |
|
34 | { |
||
35 | 363 | if (!$client) { |
|
36 | 51 | $client = self::buildClient(); |
|
37 | } |
||
38 | |||
39 | 363 | $this->client = $client; |
|
40 | 363 | } |
|
41 | |||
42 | /** |
||
43 | * Factory method to create the Guzzle 6 adapter with custom Guzzle configuration. |
||
44 | */ |
||
45 | public static function createWithConfig(array $config): Client |
||
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 204 | public function sendRequest(RequestInterface $request): ResponseInterface |
|
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | 363 | public function sendAsyncRequest(RequestInterface $request) |
|
69 | |||
70 | /** |
||
71 | * Build the Guzzle client instance. |
||
72 | */ |
||
73 | 51 | private static function buildClient(array $config = []): GuzzleClient |
|
81 | } |
||
82 |