1 | <?php declare(strict_types = 1); |
||
30 | class Tmdb implements TmdbInterface |
||
31 | { |
||
32 | |||
33 | /** |
||
34 | * API Key |
||
35 | * @var string |
||
36 | */ |
||
37 | private $api_key = null; |
||
38 | |||
39 | /** |
||
40 | * API configuration |
||
41 | * @var \stdClass |
||
42 | */ |
||
43 | protected $configuration = null; |
||
44 | |||
45 | /** |
||
46 | * API Genres |
||
47 | * @var \stdClass |
||
48 | */ |
||
49 | protected $genres = null; |
||
50 | |||
51 | /** |
||
52 | * Base URL of the API |
||
53 | * @var string |
||
54 | */ |
||
55 | public $base_api_url = 'https://api.themoviedb.org/'; |
||
56 | |||
57 | /** |
||
58 | * Logger |
||
59 | * @var LoggerInterface |
||
60 | */ |
||
61 | protected $logger = null; |
||
62 | |||
63 | /** |
||
64 | * API Version |
||
65 | * @var int |
||
66 | */ |
||
67 | protected $version = 3; |
||
68 | |||
69 | /** |
||
70 | * Http request object |
||
71 | * @var HttpRequestInterface |
||
72 | */ |
||
73 | protected $http_request = null; |
||
74 | /** |
||
75 | * Request object |
||
76 | * @var \stdClass |
||
77 | */ |
||
78 | protected $request; |
||
79 | /** |
||
80 | * Last request url |
||
81 | * @var string |
||
82 | */ |
||
83 | protected $url = null; |
||
84 | |||
85 | /** |
||
86 | * Constructor |
||
87 | * @param string $api_key TMDB API Key |
||
88 | * @param int $version Version of API (Not yet used) |
||
89 | * @param LoggerInterface $logger Logger used in the class |
||
90 | * @param HttpRequestInterface $http_request |
||
91 | */ |
||
92 | 356 | public function __construct(string $api_key, int $version = 3, LoggerInterface $logger, HttpRequestInterface $http_request) |
|
100 | |||
101 | /** |
||
102 | * Send request to TMDB API with GET method |
||
103 | * @param string $action API action to request |
||
104 | * @param array $options Array of options of the request (optional) |
||
105 | * @return \stdClass|null |
||
106 | */ |
||
107 | 317 | public function getRequest(string $action, array $options = array()) : ?\stdClass |
|
113 | |||
114 | /** |
||
115 | * Send request to TMDB API with POST method |
||
116 | * @param string $action API action to request |
||
117 | * @param array $options Array of options of the request (optional) |
||
118 | * @param array $form_params form_params for request options |
||
119 | * @return \stdClass|null |
||
120 | */ |
||
121 | 15 | public function postRequest(string $action, array $options = array(), array $form_params = array()) : ?\stdClass |
|
127 | |||
128 | /** |
||
129 | * Send request to TMDB API with DELETE method |
||
130 | * @param string $action API action to request |
||
131 | * @param array $options Array of options of the request (optional) |
||
132 | * @return \stdClass|null |
||
133 | */ |
||
134 | 5 | public function deleteRequest(string $action, array $options = array()) : ?\stdClass |
|
140 | |||
141 | /** |
||
142 | * Send request to TMDB API with GET method |
||
143 | * @param string $method HTTP method (GET, POST) |
||
144 | * @param string $url API url to request |
||
145 | * @param array $form_params form params request options |
||
146 | * @return \stdClass|null |
||
147 | */ |
||
148 | 6 | protected function sendRequest(string $method, string $url, array $form_params = array()) : ?\stdClass |
|
161 | |||
162 | /** |
||
163 | * Decode request response |
||
164 | * @param mixed $res |
||
165 | * @param string $method |
||
166 | * @param string $url |
||
167 | * @param array $form_params |
||
168 | * @return \stdClass |
||
169 | */ |
||
170 | 6 | private function decodeRequest($res, $method, $url, $form_params) : \stdClass |
|
183 | |||
184 | /** |
||
185 | * Build URL for HTTP Call |
||
186 | * @param string $action API action to request |
||
187 | * @param array $options Array of options of the request (optional) |
||
188 | * @return string |
||
189 | */ |
||
190 | 319 | private function buildHTTPUrl(string $action, array $options) : string |
|
206 | |||
207 | /** |
||
208 | * Get API Configuration |
||
209 | * @return \stdClass |
||
210 | * @throws TmdbException |
||
211 | */ |
||
212 | 50 | public function getConfiguration() : \stdClass |
|
225 | |||
226 | /** |
||
227 | * Get logger |
||
228 | * @return LoggerInterface |
||
229 | */ |
||
230 | 324 | public function getLogger() : LoggerInterface |
|
234 | |||
235 | /** |
||
236 | * Magical property getter |
||
237 | * @param string $name Name of the property |
||
238 | * @return string Value of the property |
||
239 | */ |
||
240 | 73 | public function __get(string $name) : string |
|
249 | |||
250 | /** |
||
251 | * Check year option and return correct value |
||
252 | * @param array $options |
||
253 | * @param array &$return Return array to save valid option |
||
254 | * @return void |
||
255 | */ |
||
256 | 29 | public function checkOptionYear(array $options, array &$return) : void |
|
262 | |||
263 | /** |
||
264 | * Check Language string with format ISO 639-1 |
||
265 | * @param array $options |
||
266 | * @param array &$return Return array to save valid option |
||
267 | * @return void |
||
268 | */ |
||
269 | 277 | public function checkOptionLanguage(array $options, array &$return) : void |
|
280 | |||
281 | /** |
||
282 | * Check include adult option |
||
283 | * @param array $options |
||
284 | * @param array &$return Return array to save valid option |
||
285 | * @return void |
||
286 | */ |
||
287 | 29 | public function checkOptionIncludeAdult(array $options, array &$return) : void |
|
293 | |||
294 | /** |
||
295 | * Check page option |
||
296 | * @param array $options |
||
297 | * @param array &$return Return array to save valid option |
||
298 | * @return void |
||
299 | */ |
||
300 | 38 | public function checkOptionPage(array $options, array &$return) : void |
|
306 | |||
307 | /** |
||
308 | * Check sort by option |
||
309 | * @param array $options |
||
310 | * @param array &$return Return array to save valid option |
||
311 | * @return void |
||
312 | */ |
||
313 | 9 | public function checkOptionSortBy(array $options, array &$return) : void |
|
326 | |||
327 | /** |
||
328 | * Check query option |
||
329 | * @param array $options |
||
330 | * @param array &$return Return array to save valid option |
||
331 | * @return void |
||
332 | */ |
||
333 | 28 | public function checkOptionQuery(array $options, array &$return) : void |
|
339 | |||
340 | /** |
||
341 | * Check session_id option |
||
342 | * @param array $options |
||
343 | * @param array &$return Return array to save valid option |
||
344 | * @return void |
||
345 | */ |
||
346 | 7 | public function checkOptionSessionId(array $options, array &$return) : void |
|
352 | } |
||
353 |