1 | <?php |
||
5 | class HttpClient implements HttpClientInterface |
||
6 | { |
||
7 | /** |
||
8 | * Client config. |
||
9 | * |
||
10 | * @var array |
||
11 | */ |
||
12 | protected $config; |
||
13 | |||
14 | /** |
||
15 | * Assign dependencies. |
||
16 | * |
||
17 | * @param array $config |
||
18 | */ |
||
19 | 16 | public function __construct(array $config = []) |
|
20 | { |
||
21 | 16 | $this->config = $config; |
|
22 | 16 | } |
|
23 | |||
24 | /** |
||
25 | * Make a POST request. |
||
26 | * |
||
27 | * @param string $path |
||
28 | * @param mixed $body |
||
29 | * @param array $headers |
||
30 | * |
||
31 | * @return Request |
||
32 | */ |
||
33 | 8 | public function post($path, $body = null, array $headers = []) |
|
37 | |||
38 | /** |
||
39 | * Send request with HTTP client. |
||
40 | * |
||
41 | * @param string $path |
||
42 | * @param mixed $body |
||
43 | * @param string $method |
||
44 | * @param array $headers |
||
45 | * |
||
46 | * @return Response |
||
47 | */ |
||
48 | 8 | protected function request($path, $body = null, $method = 'GET', array $headers = []) |
|
55 | |||
56 | /** |
||
57 | * Create request with HTTP client. |
||
58 | * |
||
59 | * @param string $method |
||
60 | * @param string $path |
||
61 | * @param mixed $body |
||
62 | * @param array $headers |
||
63 | * |
||
64 | * @return Request |
||
65 | */ |
||
66 | 8 | protected function createRequest($method, $path, $body = null, array $headers = []) |
|
76 | |||
77 | /** |
||
78 | * Send the request. |
||
79 | * |
||
80 | * @param Request $request |
||
81 | * |
||
82 | * @return Response |
||
83 | */ |
||
84 | 4 | public function send(Request $request) |
|
109 | |||
110 | /** |
||
111 | * Build uri with possible base uri. |
||
112 | * |
||
113 | * @param string $uri |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 4 | private function buildUri($uri) |
|
125 | } |
||
126 |