1 | <?php |
||
14 | class BattlenetHttpClient |
||
15 | { |
||
16 | /** |
||
17 | * @var Repository |
||
18 | */ |
||
19 | protected $cache; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | protected $cacheKey = 'xklusive.battlenetapi.cache'; |
||
25 | |||
26 | /** |
||
27 | * Http client. |
||
28 | * |
||
29 | * @var object GuzzleHttp\Client |
||
30 | */ |
||
31 | protected $client; |
||
32 | |||
33 | /** |
||
34 | * Game name for url prefix. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $gameParam; |
||
39 | |||
40 | /** |
||
41 | * Battle.net Connection Options. |
||
42 | * |
||
43 | * @var Collection |
||
44 | */ |
||
45 | protected $options; |
||
46 | |||
47 | /** |
||
48 | * BattlnetHttpClient constructor. |
||
49 | */ |
||
50 | public function __construct(Repository $repository) |
||
57 | |||
58 | /** |
||
59 | * Make request with API url and specific URL suffix. |
||
60 | * |
||
61 | * @return Collection|ClientException |
||
62 | */ |
||
63 | protected function api() |
||
99 | |||
100 | /** |
||
101 | * Cache the api response data if cache set to true in config file. |
||
102 | * |
||
103 | * @param array $options Options |
||
104 | * @param string $method method name |
||
105 | * @param string $apiEndPoint |
||
106 | * @return Collection|ClientException |
||
107 | */ |
||
108 | public function cache($apiEndPoint, array $options, $method) |
||
131 | |||
132 | /** |
||
133 | * Get default query options from configuration file. |
||
134 | * |
||
135 | * @return Collection |
||
136 | */ |
||
137 | private function getDefaultOptions() |
||
144 | |||
145 | /** |
||
146 | * Set default option if a 'query' key is provided |
||
147 | * else create 'query' key with default options. |
||
148 | * |
||
149 | * @param Collection $options |
||
150 | * |
||
151 | * @return Collection api response |
||
152 | */ |
||
153 | private function getQueryOptions(Collection $options) |
||
168 | |||
169 | /** |
||
170 | * Get API domain provided in configuration. |
||
171 | * |
||
172 | * @return string |
||
173 | */ |
||
174 | private function getApiEndPoint() |
||
178 | |||
179 | /** |
||
180 | * Get API key provided in configuration. |
||
181 | * |
||
182 | * @return string |
||
183 | */ |
||
184 | private function getApiKey() |
||
188 | |||
189 | /** |
||
190 | * Get API locale provided in configuration. |
||
191 | * |
||
192 | * @return string |
||
193 | */ |
||
194 | private function getLocale() |
||
198 | |||
199 | /** |
||
200 | * This method wraps the given value in a collection when applicable. |
||
201 | * |
||
202 | * @return Collection |
||
203 | */ |
||
204 | public function wrapCollection($collection) |
||
212 | |||
213 | /** |
||
214 | * Build the cache configuration. |
||
215 | * |
||
216 | * @param string $method |
||
217 | */ |
||
218 | private function buildCahceOptions($method) |
||
233 | } |
||
234 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: