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 | 9 | 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 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | 1 | public function findMoviesByQuery(string $query, string $locale = 'en', $data = []): array |
|
55 | |||
56 | /** |
||
57 | * @param int $tmdb_id |
||
58 | * @param string $locale |
||
59 | * @return array |
||
60 | * @throws TmdbMovieNotFoundException |
||
61 | * @throws TmdbRequestLimitException |
||
62 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
63 | */ |
||
64 | 1 | public function findMovieById(int $tmdb_id, string $locale = 'en'): array |
|
88 | |||
89 | /** |
||
90 | * @param int $movieId |
||
91 | * @param string $locale |
||
92 | * @return array |
||
93 | * @throws TmdbMovieNotFoundException |
||
94 | * @throws TmdbRequestLimitException |
||
95 | */ |
||
96 | public function findActorsByMovieId(int $movieId, string $locale = 'en'): array |
||
107 | |||
108 | /** |
||
109 | * @param int $personId |
||
110 | * @param string $locale |
||
111 | * @return array |
||
112 | * @throws TmdbMovieNotFoundException |
||
113 | * @throws TmdbRequestLimitException |
||
114 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
115 | */ |
||
116 | public function findActorById(int $personId, string $locale = 'en'): array |
||
132 | |||
133 | /** |
||
134 | * @param int $personId |
||
135 | * @param string $locale |
||
136 | * @return array |
||
137 | * @throws TmdbMovieNotFoundException |
||
138 | * @throws TmdbRequestLimitException |
||
139 | */ |
||
140 | public function findActorTranslationsById(int $personId, string $locale = 'en'): array |
||
151 | |||
152 | /** |
||
153 | * @param int $tmdb_id |
||
154 | * @return array |
||
155 | * @throws TmdbMovieNotFoundException |
||
156 | * @throws TmdbRequestLimitException |
||
157 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
158 | */ |
||
159 | public function findMovieTranslationsById(int $tmdb_id): array |
||
169 | |||
170 | /** |
||
171 | * @param int $tmdb_id |
||
172 | * @param int $page |
||
173 | * |
||
174 | * @throws TmdbMovieNotFoundException |
||
175 | * @throws TmdbRequestLimitException |
||
176 | * |
||
177 | * @return array |
||
178 | */ |
||
179 | public function findSimilarMoviesById(int $tmdb_id, int $page = 1): array |
||
190 | |||
191 | /** |
||
192 | * @param string $url |
||
193 | * @param string $method |
||
194 | * @param array $params |
||
195 | * @return array |
||
196 | * @throws TmdbMovieNotFoundException |
||
197 | * @throws TmdbRequestLimitException |
||
198 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
199 | */ |
||
200 | 2 | private function request(string $url, string $method = 'GET', array $params = []): array |
|
241 | |||
242 | 2 | private function arrayAsString(array $array): string |
|
255 | |||
256 | 2 | private function getCacheKeyFromParams(string $url, string $method = 'GET', array $params = []): string |
|
261 | |||
262 | /** |
||
263 | * @param string $url |
||
264 | * @param string $method |
||
265 | * @param array $params |
||
266 | * @return array|null |
||
267 | * @throws \Psr\SimpleCache\InvalidArgumentException |
||
268 | */ |
||
269 | 2 | private function getResponseFromCache(string $url, string $method = 'GET', array $params = []): ?array |
|
277 | } |
||
278 |