1 | <?php |
||
27 | class ApiClient |
||
28 | { |
||
29 | const REGION_BR = 'br'; |
||
30 | const REGION_EUNE = 'eune'; |
||
31 | const REGION_EUW = 'euw'; |
||
32 | const REGION_JP = 'jp'; |
||
33 | const REGION_KR = 'kr'; |
||
34 | const REGION_LAN = 'lan'; |
||
35 | const REGION_LAS = 'las'; |
||
36 | const REGION_NA = 'na'; |
||
37 | const REGION_OCE = 'oce'; |
||
38 | const REGION_TR = 'tr'; |
||
39 | const REGION_RU = 'ru'; |
||
40 | |||
41 | const REGION_BR_ID = 'br1'; |
||
42 | const REGION_EUNE_ID = 'eun1'; |
||
43 | const REGION_EUW_ID = 'euw1'; |
||
44 | const REGION_JP_ID = 'jp1'; |
||
45 | const REGION_KR_ID = 'kr'; |
||
46 | const REGION_LAN_ID = 'la1'; |
||
47 | const REGION_LAS_ID = 'la2'; |
||
48 | const REGION_NA_ID = 'na1'; |
||
49 | const REGION_OCE_ID = 'oc1'; |
||
50 | const REGION_TR_ID = 'tr1'; |
||
51 | const REGION_RU_ID = 'ru'; |
||
52 | |||
53 | /** |
||
54 | * @var array |
||
55 | */ |
||
56 | public static $availableRegions = [ |
||
57 | self::REGION_BR, |
||
58 | self::REGION_EUNE, |
||
59 | self::REGION_EUW, |
||
60 | self::REGION_JP, |
||
61 | self::REGION_KR, |
||
62 | self::REGION_LAN, |
||
63 | self::REGION_LAS, |
||
64 | self::REGION_NA, |
||
65 | self::REGION_OCE, |
||
66 | self::REGION_RU, |
||
67 | self::REGION_TR, |
||
68 | ]; |
||
69 | |||
70 | public static $regionsWithIds = [ |
||
71 | self::REGION_BR => self::REGION_BR_ID, |
||
72 | self::REGION_EUNE => self::REGION_EUNE_ID, |
||
73 | self::REGION_EUW => self::REGION_EUW_ID, |
||
74 | self::REGION_JP => self::REGION_JP_ID, |
||
75 | self::REGION_KR => self::REGION_KR_ID, |
||
76 | self::REGION_LAN => self::REGION_LAN_ID, |
||
77 | self::REGION_LAS => self::REGION_LAS_ID, |
||
78 | self::REGION_NA => self::REGION_NA_ID, |
||
79 | self::REGION_OCE => self::REGION_OCE_ID, |
||
80 | self::REGION_RU => self::REGION_RU_ID, |
||
81 | self::REGION_TR => self::REGION_TR_ID, |
||
82 | ]; |
||
83 | |||
84 | /** |
||
85 | * @var string |
||
86 | 3 | */ |
|
87 | protected $region; |
||
88 | 3 | ||
89 | 1 | /** |
|
90 | * @var string |
||
91 | */ |
||
92 | 2 | protected $apiKey; |
|
93 | 2 | ||
94 | 2 | /** |
|
95 | 2 | * @var Client |
|
96 | 2 | */ |
|
97 | protected $httpClient; |
||
98 | |||
99 | /** |
||
100 | * @var AdapterInterface |
||
101 | 1 | */ |
|
102 | protected $cacheProvider; |
||
103 | 1 | ||
104 | 1 | /** |
|
105 | * @param string $region |
||
106 | * @param string $apiKey |
||
107 | * @param AdapterInterface $cache |
||
108 | * @param Client $client |
||
109 | 1 | * |
|
110 | * @throws InvalidRegionException |
||
111 | 1 | */ |
|
112 | public function __construct($region, $apiKey, AdapterInterface $cache = null, Client $client = null) |
||
123 | |||
124 | /** |
||
125 | 1 | * @param AdapterInterface $cache |
|
126 | */ |
||
127 | 1 | public function setCacheProvider(AdapterInterface $cache) |
|
131 | |||
132 | /** |
||
133 | 1 | * @return AdapterInterface |
|
134 | */ |
||
135 | 1 | public function getCacheProvider() |
|
139 | |||
140 | /** |
||
141 | 1 | * @return Client |
|
142 | */ |
||
143 | 1 | public function getHttpClient() |
|
147 | |||
148 | /** |
||
149 | 1 | * @return string |
|
150 | */ |
||
151 | 1 | public function getRegion() |
|
155 | |||
156 | /** |
||
157 | 1 | * @return string |
|
158 | */ |
||
159 | 1 | public function getApiKey() |
|
163 | |||
164 | /** |
||
165 | 1 | * @return MatchApi |
|
166 | */ |
||
167 | 1 | public function getMatchApi() |
|
171 | |||
172 | /** |
||
173 | 1 | * @return SummonerApi |
|
174 | */ |
||
175 | 1 | public function getSummonerApi() |
|
179 | |||
180 | /** |
||
181 | 1 | * @return ChampionApi |
|
182 | */ |
||
183 | 1 | public function getChampionApi() |
|
187 | |||
188 | /** |
||
189 | 1 | * @return SpectatorApi |
|
190 | */ |
||
191 | 1 | public function getFeaturedGamesApi() |
|
195 | |||
196 | /** |
||
197 | 1 | * @return MasteryApi |
|
198 | */ |
||
199 | 1 | public function getMasteriesApi() |
|
203 | |||
204 | /** |
||
205 | 1 | * @return RuneApi |
|
206 | */ |
||
207 | 1 | public function getRunesApi() |
|
211 | |||
212 | /** |
||
213 | 1 | * @return SpectatorApi |
|
214 | */ |
||
215 | 1 | public function getSpectatorApi() |
|
219 | |||
220 | /** |
||
221 | 1 | * @return LeagueApi |
|
222 | */ |
||
223 | 1 | public function getLeagueApi() |
|
227 | |||
228 | /** |
||
229 | 1 | * @return StaticDataApi |
|
230 | */ |
||
231 | 1 | public function getStaticDataApi() |
|
235 | |||
236 | /** |
||
237 | 1 | * @return StatusApi |
|
238 | */ |
||
239 | 1 | public function getStatusApi() |
|
243 | |||
244 | /** |
||
245 | 1 | * @return ChampionMasteryApi |
|
246 | */ |
||
247 | 1 | public function getChampionMasteryApi() |
|
251 | |||
252 | /** |
||
253 | 1 | * @return string |
|
254 | */ |
||
255 | 1 | public function getBaseUrl() |
|
259 | |||
260 | /** |
||
261 | 1 | * @param ApiResult $apiResult |
|
262 | * @param int $ttl |
||
263 | 1 | */ |
|
264 | public function cacheApiResult(ApiResult $apiResult, $ttl = 60) |
||
276 | } |
||
277 |
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: