承接 evinkuraga/tmdb-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

evinkuraga/tmdb-api

Composer 安装命令:

composer require evinkuraga/tmdb-api

包简介

PHP wrapper for TMDB (TheMovieDatabase) API v3. Supports two types of approaches, one modelled with repositories, models and factories. And the other by simple array access to RAW data from The Movie Database.

README 文档

README

License Build Status Code Coverage PHP & HHVM

Inspired by php-github-api, php-gitlab-api and the Symfony Community.

If you have any questions or feature requests, please visit the google+ community.

Stable

Latest Stable Version Latest Unstable Version Dependency Status Total Downloads

Currently unit tests are run on travis, with the following versions:

  • 5.6
  • 7.0
  • 7.1
  • HHVM (failures allowed)
  • nightly (failures allowed)

Features

Main features

  • An complete integration of all the TMDB API has to offer (accounts, movies, tv etc. if something is missing I haven't added the updates yet!).
  • Array implementation of the movie database (RAW)
  • Model implementation of the movie database (By making use of the repositories)
  • An ImageHelper class to help build image urls or html elements.

Other things worth mentioning

  • Retry subscriber enabled by default to handle any rate limit errors.
  • Caching subscriber enabled by default, based on max-age headers returned by TMDB, requires doctrine-cache.
  • Logging subscriber and is optional, requires monolog. Could prove useful during development.

Plug-ins

Installation

Install Composer

$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

You are not obliged to move the composer.phar file to your /usr/local/bin, it is however considered easy to have an global installation.

Add the following to your require block in composer.json config

"php-tmdb/api": "~2.1"

If your new to composer and have no clue what I'm talking about

Just create a file named composer.json in your document root:

{
    "require": {
        "php-tmdb/api": "~2.1"
    }
}

Now let's install and pull in the dependencies!

composer install

Include Composer's autoloader:

require_once dirname(__DIR__).'/vendor/autoload.php';

To use the examples provided, copy the apikey.php.dist to apikey.php and change the settings.

Constructing the Client

First we always have to construct the client:

$token  = new \Tmdb\ApiToken('your_tmdb_api_key_here');
$client = new \Tmdb\Client($token);

If you'd like to make unsecure requests (by default we use secure requests).

$client = new \Tmdb\Client($token, ['secure' => false]);

Caching is enabled by default, and uses a slow filesystem handler, which you can either:

  • Replace the path of the storage of, by supplying the option in the client:
$client = new \Tmdb\Client($token, [
    'cache' => [
        'path' => '/tmp/php-tmdb'
    ]
]);
  • Or replace the whole implementation with another CacheStorage of Doctrine:
use Doctrine\Common\Cache\ArrayCache;

$client = new \Tmdb\Client($token, [
        'cache' => [
            'handler' => new ArrayCache()
        ]
    ]
);

This will only keep cache in memory during the length of the request, see the documentation of Doctrine Cache for the available adapters.

Strongly against this, disabling cache:

$client = new \Tmdb\Client($token, [
    'cache' => [
        'enabled' => false
    ]
]);

If you want to add some logging capabilities (requires monolog/monolog), defaulting to the filesystem;

$client = new \Tmdb\Client($token, [
    'log' => [
        'enabled' => true,
        'path'    => '/var/www/php-tmdb-api.log'
    ]
]);

However during development you might like some console magic like ChromePHP or FirePHP;

$client = new \Tmdb\Client($token, [
    'log' => [
        'enabled' => true,
        'handler' => new \Monolog\Handler\ChromePHPHandler()
    ]
]);

General API Usage

If your looking for a simple array entry point the API namespace is the place to be.

$movie = $client->getMoviesApi()->getMovie(550);

If you want to provide any other query arguments.

$movie = $client->getMoviesApi()->getMovie(550, array('language' => 'en'));

Model Usage

However the library can also be used in an object oriented manner, which I reckon is the preferred way of doing things.

Instead of calling upon the client, you pass the client onto one of the many repositories and do then some work on it.

$repository = new \Tmdb\Repository\MovieRepository($client);
$movie      = $repository->load(87421);

echo $movie->getTitle();

The repositories also contain the other API methods that are available through the API namespace.

$repository = new \Tmdb\Repository\MovieRepository($client);
$topRated = $repository->getTopRated(array('page' => 3));
// or
$popular = $repository->getPopular();

Some other useful hints

Event Dispatching

Since 2.0 requests are handled by the EventDispatcher, which gives you before and after hooks, the before hook allows an event to stop propagation for the request event, meaning you are able to stop the main request from happening, you will have to set a Response object in that event though.

See the files for TmdbEvents and RequestSubscriber respectively.

Image Helper

An ImageHelper class is provided to take care of the images, which does require the configuration to be loaded:

$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
$config = $configRepository->load();

$imageHelper = new \Tmdb\Helper\ImageHelper($config);

echo $imageHelper->getHtml($image, 'w154', 154, 80);

Plug-ins

At the moment there are only two useful plug-ins that are not enabled by default, and you might want to use these:

$plugin = new \Tmdb\HttpClient\Plugin\LanguageFilterPlugin('nl');

Tries to fetch everything it can in Dutch.

$plugin = new \Tmdb\HttpClient\Plugin\AdultFilterPlugin(true);

We like naughty results, if configured this way, provide false to filter these out.

Collection Filtering

We also provide some easy methods to filter any collection, you should note however you can always implement your own filter easily by using Closures:

foreach($movie->getImages()->filter(
        function($key, $value){
            if ($value instanceof \Tmdb\Model\Image\PosterImage) { return true; }
        }
    ) as $image) {

    // do something with all poster images
}

These basic filters however are already covered in the Images collection object:

$backdrop = $movie
    ->getImages()
    ->filterBackdrops()
;

And there are more Collections which provide filters, but you will find those out along the way.

The GenericCollection and the ResultCollection

The GenericCollection holds any collection of objects (e.g. an collection of movies).

The ResultCollection is an extension of the GenericCollection, and inherits the response parameters (page, total_pages, total_results) from an result set, this can be used to create paginators.

Help & Donate

If you use this in a project whether personal or business, I'd like to know where it is being used, so please drop me an e-mail! :-)

If this project saved you a bunch of work, or you just simply appreciate my efforts, please consider donating a beer (or two ;))!

evinkuraga/tmdb-api 适用场景与选型建议

evinkuraga/tmdb-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 246 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「api」 「wrapper」 「tv show」 「tv」 「tvdb」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 evinkuraga/tmdb-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 evinkuraga/tmdb-api 我们能提供哪些服务?
定制开发 / 二次开发

基于 evinkuraga/tmdb-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 246
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 10
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 118
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-08