PHPackages                             tiagosampaio/tmdb-api-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. tiagosampaio/tmdb-api-php

ActiveLibrary[API Development](/categories/api)

tiagosampaio/tmdb-api-php
=========================

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.

3.0.0(5y ago)07MITPHPPHP &gt;=5.6.0

Since Feb 27Pushed 5y agoCompare

[ Source](https://github.com/tiagosampaio/tmdb-api-php)[ Packagist](https://packagist.org/packages/tiagosampaio/tmdb-api-php)[ Docs](https://github.com/wtfzdotnet/php-tmdb-api)[ RSS](/packages/tiagosampaio-tmdb-api-php/feed)WikiDiscussions 2.1 Synced today

READMEChangelogDependencies (9)Versions (56)Used By (0)

A PHP Wrapper for use with the [TMDB API](http://docs.themoviedb.apiary.io/).
=============================================================================

[](#a-php-wrapper-for-use-with-the-tmdb-api)

[![License](https://camo.githubusercontent.com/28f52d047cb88ab284bc3d906d2ef8618c5ad85995adf51bd969e797de8af196/68747470733a2f2f706f7365722e707567782e6f72672f7068702d746d64622f6170692f6c6963656e73652e706e67)](https://packagist.org/packages/php-tmdb/api)[![Build Status](https://camo.githubusercontent.com/5c9e7d0810d1f2a6b35ca9012d6f9309210461aa89c0c5b0639f9a0d58cb3307/68747470733a2f2f7472617669732d63692e6f72672f7068702d746d64622f6170692e7376673f6272616e63683d322e31)](https://travis-ci.org/php-tmdb/api)[![Code Coverage](https://camo.githubusercontent.com/dd73599e91b5a575c0e29822fc7969555085f6dfcf2367aa59636c76a94e114a/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f7068702d746d64622f6170692f6261646765732f636f7665726167652e706e673f623d322e31)](https://scrutinizer-ci.com/g/php-tmdb/api/?branch=2.1)[![PHP & HHVM](https://camo.githubusercontent.com/54595af7bb653077cae310ebf22aef1c535ec858a3dc0c36f40ae8ebe0ac2823/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d2533453d352e362c2532304848564d2d3838393242462e737667)](http://hhvm.h4cc.de/package/php-tmdb/api)

Inspired by [php-github-api](https://github.com/KnpLabs/php-github-api), [php-gitlab-api](https://github.com/m4tthumphrey/php-gitlab-api/) and the Symfony Community.

If you have any questions or feature requests, please visit the [google+ community](https://plus.google.com/communities/113544625011244846907).

Stable
------

[](#stable)

[![Latest Stable Version](https://camo.githubusercontent.com/3b4344680c7b57ad94bf5a548b693fdf9f77550fc413a0e63a0a11449d2c7f71/68747470733a2f2f706f7365722e707567782e6f72672f7068702d746d64622f6170692f762f737461626c652e737667)](https://packagist.org/packages/php-tmdb/api)[![Latest Unstable Version](https://camo.githubusercontent.com/c82f2c683473a93f7d75068225f31827dea977bbc8f15ad355dbc72b631a7a0f/68747470733a2f2f706f7365722e707567782e6f72672f7068702d746d64622f6170692f762f756e737461626c652e737667)](https://packagist.org/packages/php-tmdb/api)[![Dependency Status](https://camo.githubusercontent.com/9ed8bc5809c42572a222838d77f1005bd4813b439b93a738972b6b5ffc7b6c77/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535316665313334393731663738343763613030303435312f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/551fe134971f7847ca000451)[![Total Downloads](https://camo.githubusercontent.com/a1eb9ea81b8b2a966147fb02351d51795d70e6b469c7df72eedb8f08c34ba1da/68747470733a2f2f706f7365722e707567782e6f72672f7068702d746d64622f6170692f646f776e6c6f6164732e737667)](https://packagist.org/packages/php-tmdb/api)

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

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

Features
--------

[](#features)

### Main 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

[](#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
--------

[](#plug-ins)

- Symfony
    - [php-tmdb/symfony](https://github.com/php-tmdb/symfony).
- Laravel
    - [php-tmdb/laravel](https://github.com/php-tmdb/laravel).

Installation
------------

[](#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
-----------------------

[](#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](http://doctrine-common.readthedocs.org/en/latest/reference/caching.html) 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
-----------------

[](#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
-----------

[](#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
-----------------------

[](#some-other-useful-hints)

### Event Dispatching

[](#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](lib/Tmdb/Event/TmdbEvents.php) and [RequestSubscriber](lib/Tmdb/Event/RequestSubscriber.php) respectively.

### Image Helper

[](#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

[](#plug-ins-1)

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

[](#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-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 &amp; Donate
-----------------

[](#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 ;))!

[![](https://camo.githubusercontent.com/e1ff554a09e8e92bef25abc553ff05b88f45afd695877cf12f3a46558ef65b2e/68747470733a2f2f7777772e70617970616c6f626a656374732e636f6d2f656e5f55532f692f62746e2f62746e5f646f6e61746543435f4c472e676966)](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SMLZ362KQ8K8W)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity72

Established project with proven stability

 Bus Factor1

Top contributor holds 85% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~42 days

Recently: every ~139 days

Total

55

Last Release

2162d ago

Major Versions

v1.4.2 → v2.0.02015-01-25

2.1.17 → 3.0.x-dev2020-06-07

PHP version history (4 changes)v1.0.0-ALPHA1PHP &gt;=5.3.2

v2.0.0PHP &gt;=5.4.0

2.1.2PHP &gt;=5.6.0

3.0.x-devPHP &gt;=7.1.3

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e44bd4b4b077a04791cb2298a5faa8f376db4b51977b3750d5348670a0b3457?d=identicon)[tiagosampaio](/maintainers/tiagosampaio)

---

Top Contributors

[![wtfzdotnet](https://avatars.githubusercontent.com/u/639376?v=4)](https://github.com/wtfzdotnet "wtfzdotnet (613 commits)")[![yukoff](https://avatars.githubusercontent.com/u/1076681?v=4)](https://github.com/yukoff "yukoff (51 commits)")[![z38](https://avatars.githubusercontent.com/u/3948085?v=4)](https://github.com/z38 "z38 (8 commits)")[![wagnered](https://avatars.githubusercontent.com/u/6115438?v=4)](https://github.com/wagnered "wagnered (7 commits)")[![wells](https://avatars.githubusercontent.com/u/2041871?v=4)](https://github.com/wells "wells (5 commits)")[![mihaeu](https://avatars.githubusercontent.com/u/2168701?v=4)](https://github.com/mihaeu "mihaeu (4 commits)")[![thinkingmedia](https://avatars.githubusercontent.com/u/551022?v=4)](https://github.com/thinkingmedia "thinkingmedia (3 commits)")[![NMullen](https://avatars.githubusercontent.com/u/2364160?v=4)](https://github.com/NMullen "NMullen (3 commits)")[![johannesx75](https://avatars.githubusercontent.com/u/3908339?v=4)](https://github.com/johannesx75 "johannesx75 (3 commits)")[![nbraquart](https://avatars.githubusercontent.com/u/18246102?v=4)](https://github.com/nbraquart "nbraquart (2 commits)")[![MarkRedeman](https://avatars.githubusercontent.com/u/1114829?v=4)](https://github.com/MarkRedeman "MarkRedeman (2 commits)")[![okaufmann](https://avatars.githubusercontent.com/u/4414498?v=4)](https://github.com/okaufmann "okaufmann (2 commits)")[![daverdalas](https://avatars.githubusercontent.com/u/5399813?v=4)](https://github.com/daverdalas "daverdalas (1 commits)")[![migburillo](https://avatars.githubusercontent.com/u/4057053?v=4)](https://github.com/migburillo "migburillo (1 commits)")[![joelwurtz](https://avatars.githubusercontent.com/u/90466?v=4)](https://github.com/joelwurtz "joelwurtz (1 commits)")[![actioussan](https://avatars.githubusercontent.com/u/11404441?v=4)](https://github.com/actioussan "actioussan (1 commits)")[![NChief](https://avatars.githubusercontent.com/u/764468?v=4)](https://github.com/NChief "NChief (1 commits)")[![greg0ire](https://avatars.githubusercontent.com/u/657779?v=4)](https://github.com/greg0ire "greg0ire (1 commits)")[![Benjam1n](https://avatars.githubusercontent.com/u/155626316?v=4)](https://github.com/Benjam1n "Benjam1n (1 commits)")[![rjkip](https://avatars.githubusercontent.com/u/1734555?v=4)](https://github.com/rjkip "rjkip (1 commits)")

---

Tags

phpapiwrappermovietv showtvtvdbtmdb

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tiagosampaio-tmdb-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/tiagosampaio-tmdb-api-php/health.svg)](https://phpackages.com/packages/tiagosampaio-tmdb-api-php)
```

###  Alternatives

[php-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.

424378.6k16](/packages/php-tmdb-api)[wtfzdotnet/php-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.

4242.9k](/packages/wtfzdotnet-php-tmdb-api)[php-tmdb/laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

16553.3k1](/packages/php-tmdb-laravel)[php-tmdb/symfony

Symfony Bundle for TMDB (The Movie Database) API. Provides easy access to the php-tmdb/api library.

3649.7k](/packages/php-tmdb-symfony)[dariusiii/tmdb-laravel

Laravel Package for TMDB ( The Movie Database ) API. Provides easy access to the wtfzdotnet/php-tmdb-api library.

1821.1k](/packages/dariusiii-tmdb-laravel)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M647](/packages/sylius-sylius)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
