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 $responseHeaders = []; |
||
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) |
|
109 | |||
110 | /** |
||
111 | * Callback to store response headers. |
||
112 | * |
||
113 | * @param resource $curl |
||
114 | * @param string $header |
||
115 | * |
||
116 | * @return int |
||
117 | */ |
||
118 | 2 | public function headerCallback($curl, $header) |
|
128 | |||
129 | /** |
||
130 | * Prepare the request headers to be sent. |
||
131 | * |
||
132 | * @param Request $request |
||
133 | * @param array $headers |
||
134 | * |
||
135 | * @return array |
||
136 | */ |
||
137 | 4 | protected function getRequestHeaders(Request $request, $headers = []) |
|
145 | |||
146 | /** |
||
147 | * Build uri with possible base uri. |
||
148 | * |
||
149 | * @param string $uri |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 4 | private function buildUri($uri) |
|
161 | } |
||
162 |