composer require php-tmdb/symfony:^4
config/bundles.php:
return [
Tmdb\SymfonyBundle\TmdbSymfonyBundle::class => ['all' => true],
];
config/packages/tmdb_symfony.yaml:
tmdb_symfony:
api_key: "%env(TMDB_API_KEY)%"
use Tmdb\Client;
class MovieService {
public function __construct(private Client $tmdbClient) {}
}
use Tmdb\Model\Movie;
class MovieController {
public function show(Client $client, string $id) {
$movie = $client->getMovie($id);
return $this->render('movie/show.html.twig', ['movie' => $movie]);
}
}
Client in services for direct API access.MovieRepository):
class MovieService {
public function __construct(
private MovieRepository $movieRepo,
private Client $tmdbClient
) {}
}
tmdb_symfony:
options:
http:
client: Symfony\Component\HttpClient\Psr18Client
tmdb_symfony.yaml:
tmdb_symfony:
cache:
enabled: true
adapter: cache.tmdb
config/packages/cache.yaml:
framework:
cache:
pools:
cache.tmdb:
adapter: cache.adapter.filesystem
default_lifetime: 86400
php-http/cache-plugin for automatic cache handling:
composer require php-http/cache-plugin:^1.7
tmdb_symfony:
log:
enabled: true
adapter: monolog.logger.tmdb
hydration:
enabled: true
with_hydration_data: false
tmdb_symfony:
log:
hydration:
with_hydration_data: true
tmdb_image_url and tmdb_image_html filters in templates:
{{ movie.posterImage|tmdb_image_url('w500') }}
{{ movie.backdropImage|tmdb_image_html('original', null, 50)|raw }}
API Key Misconfiguration:
api_key is set in tmdb_symfony.yaml or environment variables.%env(TMDB_API_KEY)%).Caching Quirks:
cache:pool:clear cache.tmdb) if data staleness occurs.86400 seconds). Adjust based on TMDB’s rate limits.Legacy Aliases:
disable_legacy_aliases: true to avoid conflicts with custom services named tmdb.client or tmdb.movie_repository.HTTPS Enforcement:
options.secure.enabled: false only for testing (TMDB requires HTTPS in production).Enable Full Logging:
with_hydration_data: true in logging config to inspect raw API responses in the profiler.Rate Limiting:
429 Too Many Requests errors. Implement exponential backoff in custom clients if needed.Repository Auto-Wiring:
repositories.enabled: true and check repositories.xml for available services.Event Dispatcher:
hydration.event_listener_handles_hydration: true and implement Tmdb\Event\HydrationEventSubscriber.Custom Hydration:
Tmdb\Model\AbstractModel to add domain-specific logic:
class CustomMovie extends Movie {
public function getCustomField(): string {
return $this->title . " (Custom)";
}
}
Override Default Client:
Client implementation in services.yaml:
services:
Tmdb\Client:
class: App\Service\CustomTmdbClient
arguments: ['@tmdb.http_client']
Add Custom Repositories:
config/packages/tmdb_symfony.yaml:
tmdb_symfony:
repositories:
custom:
class: App\Repository\CustomRepository
How can I help you explore Laravel packages today?