This commit is contained in:
thibaud-leclere
2026-01-13 13:58:53 +01:00
commit d4a3d32e0a
70 changed files with 19078 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace App\Gateway;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class TMDBGateway
{
private const TMDB_URL = 'https://api.themoviedb.org/3';
private const SEARCH_URI = '/search/movie';
public function __construct(
private readonly HttpClientInterface $client,
#[Autowire('%env(TMDB_API_TOKEN)%')]
private readonly string $apiToken,
) {
}
public function findMovie(string $movieName)
{
$url = self::TMDB_URL.self::SEARCH_URI.'?'.http_build_query(['query' => $movieName]);
try {
$response = $this->client->request('GET', $url, ['headers' => $this->getHeaders()]);
$result = $response->getContent();
} catch (\Throwable) {
return null;
}
return json_decode($this->client->request('GET', $url, ['headers' => $this->getHeaders()])->getContent(), associative: true);
}
private function getHeaders(): array
{
return ['Authorization' => 'Bearer '.$this->apiToken, 'accept' => 'application/json'];
}
}