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 | * Default language for API response |
||
41 | * @var string |
||
42 | */ |
||
43 | private $language = 'fr-FR'; |
||
44 | |||
45 | /** |
||
46 | * Include adult content in search result |
||
47 | * @var bool |
||
48 | */ |
||
49 | private $include_adult = false; |
||
50 | |||
51 | /** |
||
52 | * API Page result |
||
53 | * @var int |
||
54 | */ |
||
55 | private $page = 1; |
||
56 | |||
57 | /** |
||
58 | * API configuration |
||
59 | * @var \stdClass |
||
60 | */ |
||
61 | protected $configuration = null; |
||
62 | |||
63 | /** |
||
64 | * API Genres |
||
65 | * @var \stdClass |
||
66 | */ |
||
67 | protected $genres = null; |
||
68 | |||
69 | /** |
||
70 | * Base URL of the API |
||
71 | * @var string |
||
72 | */ |
||
73 | public $base_api_url = 'https://api.themoviedb.org/'; |
||
74 | |||
75 | /** |
||
76 | * Logger |
||
77 | * @var LoggerInterface |
||
78 | */ |
||
79 | protected $logger = null; |
||
80 | |||
81 | /** |
||
82 | * API Version |
||
83 | * @var int |
||
84 | */ |
||
85 | protected $version = 3; |
||
86 | |||
87 | /** |
||
88 | * Http request object |
||
89 | * @var HttpRequestInterface |
||
90 | */ |
||
91 | protected $http_request = null; |
||
92 | |||
93 | /** |
||
94 | * Last request url |
||
95 | * @var string |
||
96 | */ |
||
97 | protected $url = null; |
||
98 | |||
99 | /** |
||
100 | * Constructor |
||
101 | * @param string $api_key TMDB API Key |
||
102 | * @param int $version Version of API (Not yet used) |
||
103 | * @param LoggerInterface $logger Logger used in the class |
||
104 | * @param HttpRequestInterface $http_request |
||
105 | */ |
||
106 | 359 | public function __construct(string $api_key, int $version = 3, LoggerInterface $logger, HttpRequestInterface $http_request) |
|
114 | |||
115 | /** |
||
116 | * Send request to TMDB API with GET method |
||
117 | * @param string $action API action to request |
||
118 | * @param array $options Array of options of the request (optional) |
||
119 | * @return \stdClass|null |
||
120 | */ |
||
121 | 317 | public function getRequest(string $action, array $options = array()) : ?\stdClass |
|
127 | |||
128 | /** |
||
129 | * Send request to TMDB API with POST method |
||
130 | * @param string $action API action to request |
||
131 | * @param array $options Array of options of the request (optional) |
||
132 | * @param array $form_params form_params for request options |
||
133 | * @return \stdClass|null |
||
134 | */ |
||
135 | 15 | public function postRequest(string $action, array $options = array(), array $form_params = array()) : ?\stdClass |
|
141 | |||
142 | /** |
||
143 | * Send request to TMDB API with DELETE method |
||
144 | * @param string $action API action to request |
||
145 | * @param array $options Array of options of the request (optional) |
||
146 | * @return \stdClass|null |
||
147 | */ |
||
148 | 5 | public function deleteRequest(string $action, array $options = array()) : ?\stdClass |
|
154 | |||
155 | /** |
||
156 | * Send request to TMDB API with GET method |
||
157 | * @param string $method HTTP method (GET, POST) |
||
158 | * @param string $url API url to request |
||
159 | * @param array $form_params form params request options |
||
160 | * @return \stdClass|null |
||
161 | */ |
||
162 | 6 | protected function sendRequest(string $method, string $url, array $form_params = array()) : ?\stdClass |
|
188 | |||
189 | /** |
||
190 | * Build URL for HTTP Call |
||
191 | * @param string $action API action to request |
||
192 | * @param array $options Array of options of the request (optional) |
||
193 | * @return string |
||
194 | */ |
||
195 | 319 | private function buildHTTPUrl(string $action, array $options) : string |
|
211 | |||
212 | /** |
||
213 | * Get API Configuration |
||
214 | * @return \stdClass |
||
215 | * @throws TmdbException |
||
216 | */ |
||
217 | 50 | public function getConfiguration() : \stdClass |
|
230 | |||
231 | /** |
||
232 | * Check options rules before send request |
||
233 | * @param array $options Array of options to validate |
||
234 | * @return array |
||
235 | * @throws IncorrectParamException |
||
236 | */ |
||
237 | 308 | public function checkOptions(array $options) : array |
|
273 | |||
274 | /** |
||
275 | * Check year format |
||
276 | * @param mixed $year year to validate |
||
277 | * @return int year validated |
||
278 | */ |
||
279 | 2 | private function checkYear($year) : int |
|
284 | |||
285 | /** |
||
286 | * Check language |
||
287 | * @param string $language Language string with format ISO 639-1 |
||
288 | * @return string Language string validated |
||
289 | * @throws IncorrectParamException |
||
290 | */ |
||
291 | 37 | private function checkLanguage(string $language) : string |
|
300 | |||
301 | /** |
||
302 | * Check sort direction |
||
303 | * @param string $direction direction of sorting |
||
304 | * @return string Sort string validated |
||
305 | * @throws IncorrectParamException |
||
306 | */ |
||
307 | 2 | private function checkSort(string $direction) : string |
|
318 | |||
319 | /** |
||
320 | * Get logger |
||
321 | * @return LoggerInterface |
||
322 | */ |
||
323 | 329 | public function getLogger() : LoggerInterface |
|
327 | |||
328 | /** |
||
329 | * Magical property getter |
||
330 | * @param string $name Name of the property |
||
331 | * @return string Value of the property |
||
332 | */ |
||
333 | 73 | public function __get(string $name) : string |
|
342 | } |
||
343 |
An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.
If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.