Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Tmdb Symfony Laravel Package

dominikweber81/php-tmdb-symfony

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package:
    composer require php-tmdb/symfony:^4
    
  2. Register the bundle in config/bundles.php:
    return [
        Tmdb\SymfonyBundle\TmdbSymfonyBundle::class => ['all' => true],
    ];
    
  3. Configure the bundle in config/packages/tmdb_symfony.yaml:
    tmdb_symfony:
        api_key: "%env(TMDB_API_KEY)%"
    
  4. Use the client in a service:
    use Tmdb\Client;
    
    class MovieService {
        public function __construct(private Client $tmdbClient) {}
    }
    

First Use Case: Fetching a Movie

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]);
    }
}

Implementation Patterns

Dependency Injection Workflow

  • Auto-wire the Client in services for direct API access.
  • Use repositories for domain-specific operations (e.g., MovieRepository):
    class MovieService {
        public function __construct(
            private MovieRepository $movieRepo,
            private Client $tmdbClient
        ) {}
    }
    
  • Leverage Symfony’s PSR-18 HTTP Client for caching and profiling:
    tmdb_symfony:
        options:
            http:
                client: Symfony\Component\HttpClient\Psr18Client
    

Caching Strategy

  1. Enable caching in tmdb_symfony.yaml:
    tmdb_symfony:
        cache:
            enabled: true
            adapter: cache.tmdb
    
  2. Configure cache pool in config/packages/cache.yaml:
    framework:
        cache:
            pools:
                cache.tmdb:
                    adapter: cache.adapter.filesystem
                    default_lifetime: 86400
    
  3. Use php-http/cache-plugin for automatic cache handling:
    composer require php-http/cache-plugin:^1.7
    

Logging and Debugging

  • Enable granular logging for hydration, requests, and exceptions:
    tmdb_symfony:
        log:
            enabled: true
            adapter: monolog.logger.tmdb
            hydration:
                enabled: true
                with_hydration_data: false
    
  • Log hydration data (useful for profiling):
    tmdb_symfony:
        log:
            hydration:
                with_hydration_data: true
    

Twig Integration

  • Use 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 }}
    

Gotchas and Tips

Configuration Pitfalls

  1. API Key Misconfiguration:

    • Ensure api_key is set in tmdb_symfony.yaml or environment variables.
    • Avoid hardcoding keys in config files (use %env(TMDB_API_KEY)%).
  2. Caching Quirks:

    • Cache invalidation: Manually clear the cache pool (cache:pool:clear cache.tmdb) if data staleness occurs.
    • Cache lifetime: Default is 24 hours (86400 seconds). Adjust based on TMDB’s rate limits.
  3. Legacy Aliases:

    • Disable with disable_legacy_aliases: true to avoid conflicts with custom services named tmdb.client or tmdb.movie_repository.
  4. HTTPS Enforcement:

    • Disable with options.secure.enabled: false only for testing (TMDB requires HTTPS in production).

Debugging Tips

  1. Enable Full Logging:

    • Set with_hydration_data: true in logging config to inspect raw API responses in the profiler.
  2. Rate Limiting:

    • Monitor logs for 429 Too Many Requests errors. Implement exponential backoff in custom clients if needed.
  3. Repository Auto-Wiring:

    • If repositories aren’t auto-wired, ensure repositories.enabled: true and check repositories.xml for available services.
  4. Event Dispatcher:

    • Customize hydration with hydration.event_listener_handles_hydration: true and implement Tmdb\Event\HydrationEventSubscriber.

Extension Points

  1. Custom Hydration:

    • Extend Tmdb\Model\AbstractModel to add domain-specific logic:
      class CustomMovie extends Movie {
          public function getCustomField(): string {
              return $this->title . " (Custom)";
          }
      }
      
  2. Override Default Client:

    • Bind a custom Client implementation in services.yaml:
      services:
          Tmdb\Client:
              class: App\Service\CustomTmdbClient
              arguments: ['@tmdb.http_client']
      
  3. Add Custom Repositories:

    • Register new repositories in config/packages/tmdb_symfony.yaml:
      tmdb_symfony:
          repositories:
              custom:
                  class: App\Repository\CustomRepository
      
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle