1 | <?php |
||
21 | class Client |
||
22 | { |
||
23 | const DEFAULT_OPTIONS = [ |
||
24 | 'schema' => 'https', |
||
25 | 'path' => '/', |
||
26 | 'user_agent' => 'WyriHaximus/php-api-client', |
||
27 | 'headers' => [], |
||
28 | ]; |
||
29 | |||
30 | /** |
||
31 | * @var GuzzleClient |
||
32 | */ |
||
33 | protected $handler; |
||
34 | |||
35 | /** |
||
36 | * @var LoopInterface |
||
37 | */ |
||
38 | protected $loop; |
||
39 | |||
40 | /** |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $options = []; |
||
44 | |||
45 | /** |
||
46 | * @var Hydrator |
||
47 | */ |
||
48 | protected $hydrator; |
||
49 | |||
50 | /** |
||
51 | * @var CacheInterface |
||
52 | */ |
||
53 | protected $cache; |
||
54 | |||
55 | /** |
||
56 | * @param LoopInterface $loop |
||
57 | * @param GuzzleClient $handler |
||
58 | * @param array $options |
||
59 | */ |
||
60 | 12 | public function __construct(LoopInterface $loop, GuzzleClient $handler, array $options = []) |
|
70 | |||
71 | /** |
||
72 | * @param string $path |
||
73 | * @param bool $refresh |
||
74 | * @return PromiseInterface |
||
75 | */ |
||
76 | 5 | public function request(string $path, bool $refresh = false): PromiseInterface |
|
82 | |||
83 | /** |
||
84 | * @param string $path |
||
85 | * @param bool $refresh |
||
86 | * @return PromiseInterface |
||
87 | */ |
||
88 | 5 | public function requestRaw(string $path, bool $refresh = false): PromiseInterface |
|
97 | |||
98 | /** |
||
99 | * @param UriInterface $uri |
||
100 | * @return PromiseInterface |
||
101 | */ |
||
102 | 3 | protected function checkCache(UriInterface $uri): PromiseInterface |
|
122 | |||
123 | /** |
||
124 | * @param RequestInterface $request |
||
125 | * @param ResponseInterface $response |
||
126 | */ |
||
127 | 2 | protected function storeCache(RequestInterface $request, ResponseInterface $response) |
|
145 | |||
146 | /** |
||
147 | * @param UriInterface $uri |
||
148 | * @return string |
||
149 | */ |
||
150 | 3 | protected function determineCacheKey(UriInterface $uri): string |
|
165 | |||
166 | /** |
||
167 | * @param string $string |
||
168 | * @return string |
||
169 | */ |
||
170 | 3 | protected function stripExtraSlashes(string $string): string |
|
174 | |||
175 | /** |
||
176 | * @param RequestInterface $request |
||
177 | * @param bool $refresh |
||
178 | * @return PromiseInterface |
||
179 | */ |
||
180 | 5 | public function requestPsr7(RequestInterface $request, bool $refresh = false): PromiseInterface |
|
203 | |||
204 | /** |
||
205 | * @param string $path |
||
206 | * @return RequestInterface |
||
207 | */ |
||
208 | 5 | protected function createRequest(string $path): RequestInterface |
|
214 | |||
215 | /** |
||
216 | * @return array |
||
217 | */ |
||
218 | 5 | public function getHeaders(): array |
|
226 | |||
227 | /** |
||
228 | * @param string $json |
||
229 | * @return PromiseInterface |
||
230 | */ |
||
231 | public function jsonDecode(string $json): PromiseInterface |
||
237 | |||
238 | /** |
||
239 | * @return Hydrator |
||
240 | */ |
||
241 | 1 | public function getHydrator(): Hydrator |
|
245 | |||
246 | /** |
||
247 | * @return LoopInterface |
||
248 | */ |
||
249 | 3 | public function getLoop(): LoopInterface |
|
253 | |||
254 | /** |
||
255 | * @return string |
||
256 | */ |
||
257 | 8 | public function getBaseURL(): string |
|
261 | } |
||
262 |