1 | <?php |
||
15 | class TmdbSearchService |
||
16 | { |
||
17 | private $apiKey; |
||
18 | private $client; |
||
19 | private $logger; |
||
20 | private $cache; |
||
21 | private const ApiUrl = 'https://api.themoviedb.org/3'; |
||
22 | |||
23 | 13 | public function __construct(LoggerInterface $logger, ClientInterface $client, CacheInterface $cache) |
|
30 | |||
31 | /** |
||
32 | * @param string $query |
||
33 | * @param string $locale |
||
34 | * @param array $data |
||
35 | * |
||
36 | * @throws TmdbMovieNotFoundException |
||
37 | * @throws TmdbRequestLimitException |
||
38 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
39 | * |
||
40 | * @return array |
||
41 | */ |
||
42 | 1 | public function findMoviesByQuery(string $query, string $locale = 'en', $data = []): array |
|
56 | |||
57 | /** |
||
58 | * @param int $tmdb_id |
||
59 | * @param string $locale |
||
60 | * |
||
61 | * @throws TmdbMovieNotFoundException |
||
62 | * @throws TmdbRequestLimitException |
||
63 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | 1 | public function findMovieById(int $tmdb_id, string $locale = 'en'): array |
|
91 | |||
92 | /** |
||
93 | * @param int $movieId |
||
94 | * @param string $locale |
||
95 | * |
||
96 | * @throws TmdbMovieNotFoundException |
||
97 | * @throws TmdbRequestLimitException |
||
98 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
99 | * |
||
100 | * @return array |
||
101 | */ |
||
102 | public function findActorsByMovieId(int $movieId, string $locale = 'en'): array |
||
113 | |||
114 | /** |
||
115 | * @param int $personId |
||
116 | * @param string $locale |
||
117 | * |
||
118 | * @throws TmdbMovieNotFoundException |
||
119 | * @throws TmdbRequestLimitException |
||
120 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
121 | * |
||
122 | * @return array |
||
123 | */ |
||
124 | public function findActorById(int $personId, string $locale = 'en'): array |
||
140 | |||
141 | /** |
||
142 | * @param int $personId |
||
143 | * @param string $locale |
||
144 | * |
||
145 | * @throws TmdbMovieNotFoundException |
||
146 | * @throws TmdbRequestLimitException |
||
147 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
148 | * |
||
149 | * @return array |
||
150 | */ |
||
151 | public function findActorTranslationsById(int $personId, string $locale = 'en'): array |
||
162 | |||
163 | /** |
||
164 | * @param int $tmdb_id |
||
165 | * |
||
166 | * @throws TmdbMovieNotFoundException |
||
167 | * @throws TmdbRequestLimitException |
||
168 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
169 | * |
||
170 | * @return array |
||
171 | */ |
||
172 | public function findMovieTranslationsById(int $tmdb_id): array |
||
182 | |||
183 | /** |
||
184 | * @param int $tmdb_id |
||
185 | * @param int $page |
||
186 | * |
||
187 | * @throws TmdbMovieNotFoundException |
||
188 | * @throws TmdbRequestLimitException |
||
189 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
190 | * |
||
191 | * @return array |
||
192 | */ |
||
193 | public function findSimilarMoviesById(int $tmdb_id, int $page = 1): array |
||
204 | |||
205 | /** |
||
206 | * @param string $url |
||
207 | * @param string $method |
||
208 | * @param array $params |
||
209 | * |
||
210 | * @throws TmdbMovieNotFoundException |
||
211 | * @throws TmdbRequestLimitException |
||
212 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | 2 | private function request(string $url, string $method = 'GET', array $params = []): array |
|
257 | |||
258 | 2 | private function arrayAsString(array $array): string |
|
271 | |||
272 | 2 | private function getCacheKeyFromParams(string $url, string $method = 'GET', array $params = []): string |
|
278 | |||
279 | /** |
||
280 | * @param string $url |
||
281 | * @param string $method |
||
282 | * @param array $params |
||
283 | * |
||
284 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
285 | * |
||
286 | * @return array|null |
||
287 | */ |
||
288 | 2 | private function getResponseFromCache(string $url, string $method = 'GET', array $params = []): ?array |
|
296 | } |
||
297 |