init
This commit is contained in:
0
src/Controller/.gitignore
vendored
Normal file
0
src/Controller/.gitignore
vendored
Normal file
31
src/Controller/HomepageController.php
Normal file
31
src/Controller/HomepageController.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Gateway\TMDBGateway;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpClient\Exception\ClientException;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
|
||||
class HomepageController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly TMDBGateway $TMDBGateway,
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/')]
|
||||
public function index(): Response
|
||||
{
|
||||
try {
|
||||
dd($this->TMDBGateway->searchMovie('The Batman'));
|
||||
} catch (ClientException $e) {
|
||||
dd($e->getResponse()->getInfo());
|
||||
}
|
||||
|
||||
return $this->render('homepage/index.html.twig');
|
||||
}
|
||||
}
|
||||
0
src/Entity/.gitignore
vendored
Normal file
0
src/Entity/.gitignore
vendored
Normal file
38
src/Gateway/TMDBGateway.php
Normal file
38
src/Gateway/TMDBGateway.php
Normal 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'];
|
||||
}
|
||||
}
|
||||
11
src/Kernel.php
Normal file
11
src/Kernel.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
|
||||
use Symfony\Component\HttpKernel\Kernel as BaseKernel;
|
||||
|
||||
class Kernel extends BaseKernel
|
||||
{
|
||||
use MicroKernelTrait;
|
||||
}
|
||||
8
src/Model/TMDB/TMDBMovie.php
Normal file
8
src/Model/TMDB/TMDBMovie.php
Normal file
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model\TMDB;
|
||||
|
||||
class TMDBMovie
|
||||
{
|
||||
|
||||
}
|
||||
0
src/Repository/.gitignore
vendored
Normal file
0
src/Repository/.gitignore
vendored
Normal file
Reference in New Issue
Block a user