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 | 1098 | 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 | 981 | 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 | 45 | 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 | 15 | 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 | 18 | protected function sendRequest(string $method, string $url, array $form_params = array()) : ?\stdClass |
|
160 | |||
161 | /** |
||
162 | * Decode request response |
||
163 | * @param mixed $res |
||
164 | * @param string $method |
||
165 | * @param string $url |
||
166 | * @param array $form_params |
||
167 | * @return \stdClass |
||
168 | */ |
||
169 | 18 | private function decodeRequest($res, $method, $url, $form_params) : \stdClass |
|
184 | |||
185 | /** |
||
186 | * Build URL for HTTP Call |
||
187 | * @param string $action API action to request |
||
188 | * @param array $options Array of options of the request (optional) |
||
189 | * @return string |
||
190 | */ |
||
191 | 987 | private function buildHTTPUrl(string $action, array $options) : string |
|
207 | |||
208 | /** |
||
209 | * Get API Configuration |
||
210 | * @return \stdClass |
||
211 | * @throws TmdbException |
||
212 | */ |
||
213 | 150 | public function getConfiguration() : \stdClass |
|
226 | |||
227 | /** |
||
228 | * Get logger |
||
229 | * @return LoggerInterface |
||
230 | */ |
||
231 | 1002 | public function getLogger() : LoggerInterface |
|
235 | |||
236 | /** |
||
237 | * Magical property getter |
||
238 | * @param string $name Name of the property |
||
239 | * @return string Value of the property |
||
240 | */ |
||
241 | 222 | public function __get(string $name) : string |
|
250 | |||
251 | /** |
||
252 | * Check year option and return correct value |
||
253 | * @param array $options |
||
254 | * @param array &$return Return array to save valid option |
||
255 | * @return void |
||
256 | */ |
||
257 | 87 | public function checkOptionYear(array $options, array &$return) : void |
|
263 | |||
264 | /** |
||
265 | * Check Language string with format ISO 639-1 |
||
266 | * @param array $options |
||
267 | * @param array &$return Return array to save valid option |
||
268 | * @return void |
||
269 | */ |
||
270 | 861 | public function checkOptionLanguage(array $options, array &$return) : void |
|
281 | |||
282 | /** |
||
283 | * Check include adult option |
||
284 | * @param array $options |
||
285 | * @param array &$return Return array to save valid option |
||
286 | * @return void |
||
287 | */ |
||
288 | 87 | public function checkOptionIncludeAdult(array $options, array &$return) : void |
|
294 | |||
295 | /** |
||
296 | * Check page option |
||
297 | * @param array $options |
||
298 | * @param array &$return Return array to save valid option |
||
299 | * @return void |
||
300 | */ |
||
301 | 114 | public function checkOptionPage(array $options, array &$return) : void |
|
307 | |||
308 | /** |
||
309 | * Check sort by option |
||
310 | * @param array $options |
||
311 | * @param array &$return Return array to save valid option |
||
312 | * @return void |
||
313 | */ |
||
314 | 27 | public function checkOptionSortBy(array $options, array &$return) : void |
|
327 | |||
328 | /** |
||
329 | * Check query option |
||
330 | * @param array $options |
||
331 | * @param array &$return Return array to save valid option |
||
332 | * @return void |
||
333 | */ |
||
334 | 84 | public function checkOptionQuery(array $options, array &$return) : void |
|
340 | |||
341 | /** |
||
342 | * Check session_id option |
||
343 | * @param array $options |
||
344 | * @param array &$return Return array to save valid option |
||
345 | * @return void |
||
346 | */ |
||
347 | 21 | public function checkOptionSessionId(array $options, array &$return) : void |
|
353 | } |
||
354 |