1 | <?php |
||
5 | class HttpClient implements HttpClientInterface |
||
6 | { |
||
7 | /** |
||
8 | * Client config. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $config; |
||
13 | |||
14 | /** |
||
15 | * Headers returned in the response. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $headers = []; |
||
20 | |||
21 | /** |
||
22 | * Assign dependencies. |
||
23 | * |
||
24 | * @param array $config |
||
25 | */ |
||
26 | 16 | public function __construct(array $config = []) |
|
30 | |||
31 | /** |
||
32 | * Make a POST request. |
||
33 | * |
||
34 | * @param string $path |
||
35 | * @param mixed $body |
||
36 | * @param array $headers |
||
37 | * |
||
38 | * @return Request |
||
39 | */ |
||
40 | 8 | public function post($path, $body = null, array $headers = []) |
|
44 | |||
45 | /** |
||
46 | * Send request with HTTP client. |
||
47 | * |
||
48 | * @param string $path |
||
49 | * @param mixed $body |
||
50 | * @param string $method |
||
51 | * @param array $headers |
||
52 | * |
||
53 | * @return Response |
||
54 | */ |
||
55 | 8 | protected function request($path, $body = null, $method = 'GET', array $headers = []) |
|
62 | |||
63 | /** |
||
64 | * Create request with HTTP client. |
||
65 | * |
||
66 | * @param string $method |
||
67 | * @param string $path |
||
68 | * @param mixed $body |
||
69 | * @param array $headers |
||
70 | * |
||
71 | * @return Request |
||
72 | */ |
||
73 | 8 | protected function createRequest($method, $path, $body = null, array $headers = []) |
|
83 | |||
84 | /** |
||
85 | * Send the request. |
||
86 | * |
||
87 | * @param Request $request |
||
88 | * |
||
89 | * @return Response |
||
90 | */ |
||
91 | 4 | public function send(Request $request) |
|
115 | |||
116 | /** |
||
117 | * Callback to store response headers. |
||
118 | * |
||
119 | * @param resource $curl |
||
120 | * @param string $header |
||
121 | * |
||
122 | * @return int |
||
123 | */ |
||
124 | 2 | public function headerCallback($curl, $header) |
|
134 | |||
135 | /** |
||
136 | * Build uri with possible base uri. |
||
137 | * |
||
138 | * @param string $uri |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | 4 | private function buildUri($uri) |
|
150 | } |
||
151 |