dominikweber81/php-tmdb-symfony
Composer 安装命令:
composer require dominikweber81/php-tmdb-symfony
包简介
Symfony Bundle for TMDB (The Movie Database) API. Provides easy access to the php-tmdb/api library.
README 文档
README
Compatible with Symfony 5 and 6, PHP 7.4 and up.
Buy me a coffee, or a beer :-)
My stomach will appreciate your donation!
Installation
- Install Composer
- Install php-tmdb/api dependencies
- For development within Symfony we recommend making use of Symfony's PSR-18 HTTP Client
Symfony\Component\HttpClient\Psr18Client, as when non-cached results pass your profiler will be filled with data.
- For development within Symfony we recommend making use of Symfony's PSR-18 HTTP Client
Then require the bundle:
composer require php-tmdb/symfony:^4
Configuration
Register the bundle in app/bundles.php:
<?php return [ // --- snip --- Tmdb\SymfonyBundle\TmdbSymfonyBundle::class => ['all' => true], ];
Add to your app/config/config.yml the following, or replace values with services of your choice ( PSR-18 Http Client / PSR-17 Factories ):
tmdb_symfony: api_key: YOUR_API_KEY_HERE options: http: client: Symfony\Component\HttpClient\Psr18Client request_factory: Nyholm\Psr7\Factory\Psr17Factory response_factory: Nyholm\Psr7\Factory\Psr17Factory stream_factory: Nyholm\Psr7\Factory\Psr17Factory uri_factory: Nyholm\Psr7\Factory\Psr17Factory
services.yaml:
services: Symfony\Component\HttpClient\Psr18Client: class: Symfony\Component\HttpClient\Psr18Client Nyholm\Psr7\Factory\Psr17Factory: class: Nyholm\Psr7\Factory\Psr17Factory
Configure caching
You can use any PSR-6 cache you wish to use, we will simply use symfony's cache.
When making use of caching, make sure to also include php-http/cache-plugin in composer, this plugin handles the logic for us,
so we don't have to re-invent the wheel.
You are however also free to choose to implement your own cache listener, or add the caching logic inside the http client of your choice.
composer require php-http/cache-plugin:^1.7
First off configure the cache pool in symfony config/cache.yaml:
framework: cache: pools: cache.tmdb: adapter: cache.adapter.filesystem default_lifetime: 86400
Then in your tmdb_symfony.yaml configuration enable the cache and reference this cache pool:
tmdb_symfony: api_key: YOUR_API_KEY_HERE cache: enabled: true adapter: cache.tmdb
Want to make use of logging?
Logging capabilities as of 4.0 allow you to make a fine-grained configuration.
You can use any PSR-3 logger you wish to use, we will simply use monolog.
First off configure the monolog and add a channel and handler:
monolog: channels: - tmdb handlers: tmdb: type: stream path: "%kernel.logs_dir%/php-tmdb--symfony.%kernel.environment%.log" level: info channels: ["tmdb"]
Then in your tmdb_symfony.yaml configuration:
tmdb_symfony: api_key: YOUR_API_KEY_HERE log: enabled: true adapter: monolog.logger.tmdb hydration: enabled: true with_hydration_data: false # We would only recommend to enable this with an in-memory logger, so you have access to the hydration data within the profiler. adapter: null # you can set different adapters for different logs, leave null to use the main adapter. listener: Tmdb\Event\Listener\Logger\LogHydrationListener formatter: Tmdb\Formatter\Hydration\SimpleHydrationFormatter request_logging: enabled: true adapter: null # you can set different adapters for different logs, leave null to use the main adapter. listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter response_logging: enabled: true adapter: null # you can set different adapters for different logs, leave null to use the main adapter. listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter api_exception_logging: enabled: true adapter: null # you can set different adapters for different logs, leave null to use the main adapter. listener: Tmdb\Event\Listener\Logger\LogApiErrorListener formatter: Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter client_exception_logging: enabled: true adapter: null # you can set different adapters for different logs, leave null to use the main adapter. listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter
Disable repositories :
tmdb_symfony: api_key: YOUR_API_KEY_HERE repositories: enabled: false
Disable twig extension :
tmdb_symfony: api_key: YOUR_API_KEY_HERE twig_extension: enabled: false
Disable https :
tmdb_symfony: api_key: YOUR_API_KEY_HERE options: secure: enabled: false
Disable legacy aliases :
Set to true to remove all legacy alises ( e.g. tmdb.client or tmdb.movie_repository ).
tmdb_symfony: api_key: YOUR_API_KEY_HERE disable_legacy_aliases: true
Full configuration with defaults :
tmdb_symfony: api_key: YOUR_API_KEY_HERE cache: enabled: true adapter: cache.tmdb log: enabled: true adapter: monolog.logger.tmdb hydration: enabled: true with_hydration_data: false adapter: null listener: Tmdb\Event\Listener\Logger\LogHydrationListener formatter: Tmdb\Formatter\Hydration\SimpleHydrationFormatter request_logging: enabled: true adapter: null listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter response_logging: enabled: true adapter: null listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter api_exception_logging: enabled: true adapter: null listener: Tmdb\Event\Listener\Logger\LogApiErrorListener formatter: Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter client_exception_logging: enabled: true adapter: null listener: Tmdb\Event\Listener\Logger\LogHttpMessageListener formatter: Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter options: bearer_token: YOUR_BEARER_TOKEN_HERE http: client: Symfony\Component\HttpClient\Psr18Client request_factory: Nyholm\Psr7\Factory\Psr17Factory response_factory: Nyholm\Psr7\Factory\Psr17Factory stream_factory: Nyholm\Psr7\Factory\Psr17Factory uri_factory: Nyholm\Psr7\Factory\Psr17Factory secure: true host: api.themoviedb.org/3 guest_session_token: null event_dispatcher: adapter: event_dispatcher hydration: event_listener_handles_hydration: false only_for_specified_models: { } api_token: YOUR_API_KEY_HERE # you don't have to set this if you set it at the root level session_token: null repositories: enabled: true twig_extension: enabled: true disable_legacy_aliases: false
Usage
Obtaining the client
<?php namespace App; use Tmdb\Client; class MovieParser { private Client $client; // Have Symfony auto-wire the client via your constructor public function __construct(Client $client) { $this->client = $client; } }
Obtaining repositories
<?php namespace App; use Tmdb\Model\AbstractModel; use Tmdb\Repository\MovieRepository; class MovieParser { private MovieRepository $movieRepository; // Have Symfony auto-wire the repository via your constructor public function __construct(MovieRepository $movieRepository) { $this->movieRepository = $movieRepository; } public function findMovie(string $id): AbstractModel { // Use the auto-wired repository in any of your methods return $this->movieRepository->load($id); } }
An overview of all the repositories can be found in the services configuration repositories.xml.
There is also a Twig helper that makes use of the Tmdb\Helper\ImageHelper to output urls and html.
{{ movie.backdropImage|tmdb_image_url }}
{{ movie.backdropImage|tmdb_image_html('original', null, 50)|raw }}
For all all other interactions take a look at php-tmdb/api.
dominikweber81/php-tmdb-symfony 适用场景与选型建议
dominikweber81/php-tmdb-symfony 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 07 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「symfony」 「php」 「api」 「wrapper」 「tv show」 「tv」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 dominikweber81/php-tmdb-symfony 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 dominikweber81/php-tmdb-symfony 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 dominikweber81/php-tmdb-symfony 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The bundle for easy using json-rpc api on your project
A PSR-7 compatible library for making CRUD API endpoints
Bundle Symfony DaplosBundle
Alfabank REST API integration
Biblioteca PHP pura para pagamentos SISP/Vinti4 de Cabo Verde.
Zero-dependency raw PHP DNS resolver, domain-ownership verification, and intoDNS/MxToolbox-style diagnostics. Queries authoritative nameservers directly over sockets — never trusts the recursive cache for ownership checks.
统计信息
- 总下载量: 8
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-10