1 | <?php |
||
35 | class Client implements IClient { |
||
36 | /** @var GuzzleClient */ |
||
37 | private $client; |
||
38 | /** @var IConfig */ |
||
39 | private $config; |
||
40 | /** @var ICertificateManager */ |
||
41 | private $certificateManager; |
||
42 | |||
43 | /** |
||
44 | * @param IConfig $config |
||
45 | * @param ICertificateManager $certificateManager |
||
46 | * @param GuzzleClient $client |
||
47 | */ |
||
48 | 9 | public function __construct(IConfig $config, |
|
56 | |||
57 | /** |
||
58 | * Sets the default options to the client |
||
59 | */ |
||
60 | 9 | private function setDefaultOptions() { |
|
74 | |||
75 | /** |
||
76 | * Get the proxy URI |
||
77 | * @return string |
||
78 | */ |
||
79 | 9 | private function getProxyUri() { |
|
93 | |||
94 | /** |
||
95 | * Sends a GET request |
||
96 | * @param string $uri |
||
97 | * @param array $options Array such as |
||
98 | * 'query' => [ |
||
99 | * 'field' => 'abc', |
||
100 | * 'other_field' => '123', |
||
101 | * 'file_name' => fopen('/path/to/file', 'r'), |
||
102 | * ], |
||
103 | * 'headers' => [ |
||
104 | * 'foo' => 'bar', |
||
105 | * ], |
||
106 | * 'cookies' => [' |
||
107 | * 'foo' => 'bar', |
||
108 | * ], |
||
109 | * 'allow_redirects' => [ |
||
110 | * 'max' => 10, // allow at most 10 redirects. |
||
111 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
112 | * 'referer' => true, // add a Referer header |
||
113 | * 'protocols' => ['https'] // only allow https URLs |
||
114 | * ], |
||
115 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
116 | * 'verify' => true, // bool or string to CA file |
||
117 | * 'debug' => true, |
||
118 | * 'timeout' => 5, |
||
119 | * @return Response |
||
120 | * @throws \Exception If the request could not get completed |
||
121 | */ |
||
122 | 1 | public function get($uri, array $options = []) { |
|
127 | |||
128 | /** |
||
129 | * Sends a HEAD request |
||
130 | * @param string $uri |
||
131 | * @param array $options Array such as |
||
132 | * 'headers' => [ |
||
133 | * 'foo' => 'bar', |
||
134 | * ], |
||
135 | * 'cookies' => [' |
||
136 | * 'foo' => 'bar', |
||
137 | * ], |
||
138 | * 'allow_redirects' => [ |
||
139 | * 'max' => 10, // allow at most 10 redirects. |
||
140 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
141 | * 'referer' => true, // add a Referer header |
||
142 | * 'protocols' => ['https'] // only allow https URLs |
||
143 | * ], |
||
144 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
145 | * 'verify' => true, // bool or string to CA file |
||
146 | * 'debug' => true, |
||
147 | * 'timeout' => 5, |
||
148 | * @return Response |
||
149 | * @throws \Exception If the request could not get completed |
||
150 | */ |
||
151 | public function head($uri, $options = []) { |
||
155 | |||
156 | /** |
||
157 | * Sends a POST request |
||
158 | * @param string $uri |
||
159 | * @param array $options Array such as |
||
160 | * 'body' => [ |
||
161 | * 'field' => 'abc', |
||
162 | * 'other_field' => '123', |
||
163 | * 'file_name' => fopen('/path/to/file', 'r'), |
||
164 | * ], |
||
165 | * 'headers' => [ |
||
166 | * 'foo' => 'bar', |
||
167 | * ], |
||
168 | * 'cookies' => [' |
||
169 | * 'foo' => 'bar', |
||
170 | * ], |
||
171 | * 'allow_redirects' => [ |
||
172 | * 'max' => 10, // allow at most 10 redirects. |
||
173 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
174 | * 'referer' => true, // add a Referer header |
||
175 | * 'protocols' => ['https'] // only allow https URLs |
||
176 | * ], |
||
177 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
178 | * 'verify' => true, // bool or string to CA file |
||
179 | * 'debug' => true, |
||
180 | * 'timeout' => 5, |
||
181 | * @return Response |
||
182 | * @throws \Exception If the request could not get completed |
||
183 | */ |
||
184 | 1 | public function post($uri, array $options = []) { |
|
188 | |||
189 | /** |
||
190 | * Sends a PUT request |
||
191 | * @param string $uri |
||
192 | * @param array $options Array such as |
||
193 | * 'body' => [ |
||
194 | * 'field' => 'abc', |
||
195 | * 'other_field' => '123', |
||
196 | * 'file_name' => fopen('/path/to/file', 'r'), |
||
197 | * ], |
||
198 | * 'headers' => [ |
||
199 | * 'foo' => 'bar', |
||
200 | * ], |
||
201 | * 'cookies' => [' |
||
202 | * 'foo' => 'bar', |
||
203 | * ], |
||
204 | * 'allow_redirects' => [ |
||
205 | * 'max' => 10, // allow at most 10 redirects. |
||
206 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
207 | * 'referer' => true, // add a Referer header |
||
208 | * 'protocols' => ['https'] // only allow https URLs |
||
209 | * ], |
||
210 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
211 | * 'verify' => true, // bool or string to CA file |
||
212 | * 'debug' => true, |
||
213 | * 'timeout' => 5, |
||
214 | * @return Response |
||
215 | * @throws \Exception If the request could not get completed |
||
216 | */ |
||
217 | 1 | public function put($uri, array $options = []) { |
|
221 | |||
222 | /** |
||
223 | * Sends a DELETE request |
||
224 | * @param string $uri |
||
225 | * @param array $options Array such as |
||
226 | * 'body' => [ |
||
227 | * 'field' => 'abc', |
||
228 | * 'other_field' => '123', |
||
229 | * 'file_name' => fopen('/path/to/file', 'r'), |
||
230 | * ], |
||
231 | * 'headers' => [ |
||
232 | * 'foo' => 'bar', |
||
233 | * ], |
||
234 | * 'cookies' => [' |
||
235 | * 'foo' => 'bar', |
||
236 | * ], |
||
237 | * 'allow_redirects' => [ |
||
238 | * 'max' => 10, // allow at most 10 redirects. |
||
239 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
240 | * 'referer' => true, // add a Referer header |
||
241 | * 'protocols' => ['https'] // only allow https URLs |
||
242 | * ], |
||
243 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
244 | * 'verify' => true, // bool or string to CA file |
||
245 | * 'debug' => true, |
||
246 | * 'timeout' => 5, |
||
247 | * @return Response |
||
248 | * @throws \Exception If the request could not get completed |
||
249 | */ |
||
250 | 1 | public function delete($uri, array $options = []) { |
|
254 | |||
255 | |||
256 | /** |
||
257 | * Sends a options request |
||
258 | * @param string $uri |
||
259 | * @param array $options Array such as |
||
260 | * 'body' => [ |
||
261 | * 'field' => 'abc', |
||
262 | * 'other_field' => '123', |
||
263 | * 'file_name' => fopen('/path/to/file', 'r'), |
||
264 | * ], |
||
265 | * 'headers' => [ |
||
266 | * 'foo' => 'bar', |
||
267 | * ], |
||
268 | * 'cookies' => [' |
||
269 | * 'foo' => 'bar', |
||
270 | * ], |
||
271 | * 'allow_redirects' => [ |
||
272 | * 'max' => 10, // allow at most 10 redirects. |
||
273 | * 'strict' => true, // use "strict" RFC compliant redirects. |
||
274 | * 'referer' => true, // add a Referer header |
||
275 | * 'protocols' => ['https'] // only allow https URLs |
||
276 | * ], |
||
277 | * 'save_to' => '/path/to/file', // save to a file or a stream |
||
278 | * 'verify' => true, // bool or string to CA file |
||
279 | * 'debug' => true, |
||
280 | * 'timeout' => 5, |
||
281 | * @return Response |
||
282 | * @throws \Exception If the request could not get completed |
||
283 | */ |
||
284 | 1 | public function options($uri, array $options = []) { |
|
288 | } |
||
289 |