use_models config, but Laravel’s Eloquent models would need alignment with the bundle’s Model classes (e.g., Movie, TvShow).AppKernel, YAML config). Requires:
TmdbFacade)..env or config/tmdb.php.spatie/laravel-tmdb).Symfony/Bundle, Symfony/DependencyInjection) unnecessarily for a Laravel project.Model classes may clash with Laravel’s Eloquent or native PHP types.Kernel, Bundle system). Requires decoupling.HttpClient under the hood (could be swapped for Guzzle/PHP’s curl).Tmdb) to hide Symfony-specific code.AppServiceProvider.config/tmdb.php for Laravel’s .env support.Installation:
composer require bogdanfinn/tmdb-bundle
Configuration:
config.yml with Laravel’s config/tmdb.php:
// config/tmdb.php
return [
'api_key' => env('TMDB_API_KEY'),
'use_models' => env('TMDB_USE_MODELS', false),
];
.env:
TMDB_API_KEY=your_key_here
TMDB_USE_MODELS=false # Recommended to avoid model conflicts
Service Registration:
AppServiceProvider::boot():
$this->app->singleton('tmdb.client', function ($app) {
return new \bogdanfinn\tmdbBundle\Service\TvShowClient(
$app['tmdb.config'],
new \Symfony\Contracts\HttpClient\HttpClient() // Or Guzzle
);
});
app/Facades/Tmdb.php):
namespace App\Facades;
use Illuminate\Support\Facades\Facade;
class Tmdb extends Facade {
protected static function getFacadeAccessor() { return 'tmdb.client'; }
}
Usage:
use App\Facades\Tmdb;
$tvShow = Tmdb::getTvShow(123); // Returns JSON or model (if enabled)
HttpClient is mocked or replaced.Model classes (e.g., Movie) are Symfony-specific. Avoid use_models: true unless:
Arrayable, Jsonable).use_models: false to return raw JSON.composer.json.use_models: false to avoid model-related issues.spatie/laravel-caching).HttpClient is generally thread-safe, but test under load.| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Bundle API key invalid | All TMDb calls fail | Validate .env key early (e.g., in bootstrap/app.php). |
| Symfony dependency conflicts | Laravel app crashes | Isolate bundle in a separate namespace/class. |
| TMDb API downtime | Feature breaks | Implement fallback responses or retries. |
| Model serialization issues | Data corruption | Avoid use_models: true; use JSON parsing. |
| Bundle abandonment | Unmaintained code | Fork or migrate to a Laravel-native solution. |
Container, Bundle) may be unfamiliar to Laravel devs.spatie/laravel-tmdb if available).How can I help you explore Laravel packages today?