Download the PHP package wtfzdotnet/php-tmdb-api without Composer
On this page you can find all versions of the php package wtfzdotnet/php-tmdb-api. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download wtfzdotnet/php-tmdb-api
More information about wtfzdotnet/php-tmdb-api
Files in wtfzdotnet/php-tmdb-api
Package php-tmdb-api
Short Description 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.
License MIT
Homepage https://github.com/php-tmdb/api
Informations about the package php-tmdb-api
A PHP Wrapper for use with the TMDB API.
Tests run with minimal, normal and development dependencies.
Buy me a coffee, or a beer :-)
My stomach will appreciate your donation!
Main features
- 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.
Attention newcomers to php
If you are new to php and starting a project to learn, I'd recommend you skip down to the installation, and then follow the quickstart that's just for you!
I do advise you to take a broader look later on what all these PSR standards mean and do for the php community :-).
PSR Compliance
We try to leave as many options open to the end users of this library, as such with 4.0 changes have been made to introduce PSR compliance where we can. You bring the dependencies you prefer that are compliant with PSR standards, register the listeners, and we handle the rest.
- PSR-3: Logger Interface, jump to section.
- Logs TMDB API exceptions, jump to section.
- Logs PSR-18 client exceptions, jump to section.
- Logs requests and responses, jump to section.
- Logs response hydration, jump to section.
- Logs caching behavior , jump to section.
- PSR-6: Caching Interface, jump to section.
- PSR-7: HTTP Message Interface
- Requests and responses will be modified via relevant event listeners.
- PSR-12: Extended Coding Style.
- Work in progress, I'll do my best to finish before
4.1
but there is a lot to review and refactor. It would be nice to get contributions going our way helping out with this massive task. I can imagine it may take several months of doing small bits here and there to achieve this.
- Work in progress, I'll do my best to finish before
- PSR-14: Event Dispatcher, jump to section.
- Register our listeners and events, we handle the rest.
- PSR-16: Simple Cache, by adapting to PSR-6
- Although we do not implement this at the current stage, there are plenty of adapters converting
PSR-16
implementations toPSR-6
. - We might rework this at a later stage to prevent the extra dependencies that the
php-http/cache-plugin
brings along.
- Although we do not implement this at the current stage, there are plenty of adapters converting
- PSR-17: HTTP Factories
- Bring along the http factories of your choice.
- PSR-18: HTTP Client
- Bring along the PSR-18 http client of your choice.
Framework implementations
- Symfony (maintained by php-tmdb developers)
- Laravel (community maintained)
Installation
Install composer.
Before we can install the api library, you need to install a set of dependencies that provide the following implementations.
Dependencies you have to fulfill yourself
- For
PSR-7: HTTP Message Interface
, for examplenyholm/psr7
. - For
PSR-14: Event Dispatcher
, for examplesymfony/event-dispatcher
. - For
PSR-17: HTTP Factories
, for examplenyholm/psr7
. - For
PSR-18: HTTP Client
, for exampleguzzlehttp/guzzle
.
I urge you to implement the optional caching implementation
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.
Even though themoviedb.org disabled rate limiting since the end of 2019,
I'd still recommend enabling the cache to make your application run a bit smoother. As such the 427
retry subscriber in previous versions is not present anymore.
- For
PSR-6: Caching Interface
, for examplesymfony/cache
. - For
PSR-16: Simple Cache
, with an PSR-6 adapter for examplesymfony/cache
, then use the PSR-16 to PSR-6 adapter.
Not only will this make your application more responsive, by loading from cache when we can, it also decreases the amount of requests we need to send.
Optional dependencies
- For
PSR-3: Logger Interface
, for examplemonolog/monolog
.
Install php-tmdb/api
If the required dependencies above are met, you are ready to install the library.
Include Composer's autoloader:
To use the examples provided, copy the examples/apikey.php.dist
to examples/apikey.php
and change the settings.
New to PSR standards or composer?
If you came here looking to start a fun project to start learning, the above might seem a little daunting.
Don't worry! The documentation here was setup with beginners in mind as well.
We also provide a bunch of examples in the examples/
folder.
To get started;
Now that we have everything we need installed, let's get started setting up to be able to use the library.
Quick setup
Review the setup files below and go over the examples folder, for example examples/movies/api/get.php files.
Constructing the Client
If you have chosen different implementations than the examples suggested beforehand, obviously all the upcoming documentation won't match. Adjust accordingly to your dependencies, we will go along with the examples given earlier.
- Minimal setup
- Minimal setup with psr-6 caching
- Full setup
- Includes logging
- Includes caching
- Includes filtering by region
- Includes filtering by language
- Includes filtering by adult content
General API Usage
If you're looking for a simple array entry point the API namespace is the place to be, however we recommend you use the repositories and model's functionality up ahead.
If you want to provide any other query arguments.
For all further calls just review the examples provided, or the API classes themselves.
Model Usage
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.
The repositories also contain the other API methods that are available through the API namespace.
For all further calls just review the examples provided, or the model's themselves.
Event Dispatching
We (can) dispatch the following events inside the library, which by using event listeners you could modify some behavior.
HTTP Client exceptions
Tmdb\Event\HttpClientExceptionEvent
- Allows to still set a successful response if the error can be corrected, by calling
$event->isPropagated()
in your listener, this does require you to provide a PSR-7 response object and set it with$event->setResponse($response)
.
- Allows to still set a successful response if the error can be corrected, by calling
TMDB API exceptions
Tmdb\Event\TmdbExceptionEvent
- Allows to still set a successful response if the error can be corrected, by calling
$event->isPropagated()
in your listener, this does require you to provide a PSR-7 response object and set it with$event->setResponse($response)
.
- Allows to still set a successful response if the error can be corrected, by calling
Hydration
Tmdb\Event\BeforeHydrationEvent
, allows modification of the response data before being hydrated.- This event will still be thrown regardless if the
event_listener_handles_hydration
option is set to false, this allows for example the logger to still produce records.
- This event will still be thrown regardless if the
Tmdb\Event\AfterHydrationEvent
, allows modification of the eventual subject returned.
The current implementation within the event dispatcher causes significant overhead, you might actually not want at all.
In the future we will look into this further for improvement, for now we have bigger fish to catch.
From 4.0
moving forward by default the hydration events have been disabled.
To re-enable this functionality, we recommend only using it for models you need to modify data for;
If that configuration has been applied, also make sure the event dispatcher you use is aware of our HydrationListener
;
If you re-enable this functionality without specifying any models, all hydration will be done through the event listeners.
Requests & Responses
Tmdb\Event\BeforeRequestEvent
- Allows modification of the PSR-7 request data before being sent.
- Allows early response behavior ( think of caching ), by calling
$event->isPropagated()
in your listener, this does require you to provide a PSR-7 response object and set it with$event->setResponse($response)
Tmdb\Event\ResponseEvent
- Contains the
Request
object. - Allows modification of the PSR-7 response before being hydrated, this does require you to provide a PSR-7
response object and set it with
$event->setResponse($response)
- Allows end-user to implement their own cache, or any other actions you'd like to perform on the given response.
- Contains the
Event listeners
We have a couple of optional event listeners that you could add to provide additional functionality.
Caching
Instead of constructing the default RequestListener
, construct the client with the Psr6CachedRequestListener
.
The current implementation will change again in the future, it will either involve a small change in listener registration,
or will just happen without you being aware. We currently base this on php-http/cache-plugin
, which pulls in extra
dependencies we don't really use. Since caching is quite a subject itself, for now we have chosen the "quick 'n dirty way".
Logging
The logging is divided in a couple of listeners, so you can decide what you want to log, or not. All of these
listeners have support for writing custom formatted messages. See the relevant interfaces and classes located in the
Tmdb\Formatter
namespace.
Instead of monolog you can pass any PSR-3 compatible logger.
Tmdb\Event\Listener\Logger\LogApiErrorListener
This will log exceptions thrown when a response has successfully been received, but the response indicated the request was not successful.
Tmdb\Event\Listener\Logger\LogHttpMessageListener
This will log outgoing requests and responses.
In case of any other PSR-18 client exceptions ( connection errors for example ), these will also be written to the log.
Tmdb\Event\Listener\Logger\LogHydrationListener
This will log hydration of models with (optionally) their data, useful for debugging.
For calls with a lot of appended data, this quickly becomes a large dump in the log file, and I would advise to only use this when necessary.
Do not enable the hydration data dumping on production, it will generate massive logs.
Adult filter
To enable inclusion of results considered "adult", add the following listener.
Language filter
To enable filtering contents on language, add the following listener.
Region filter
To enable filtering contents on region, add the following listener.
Guest session
If you want to make use of guest sessions, you need to specify this explicitly on the client.
Image Helper
An ImageHelper
class is present to take care of the images, which does require the configuration to be loaded:
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:
These basic filters however are already covered in the Images
collection object:
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 theGenericCollection
, and inherits the response parameters _(page, total_pages, totalresults) from an result set, this can be used to create pagination.
All versions of php-tmdb-api with dependencies
ext-json Version *
symfony/options-resolver Version >=4.4 || ^5 || ^6
psr/cache Version ^1 || ^2 || ^3
psr/simple-cache Version ^1 || ^2 || ^3
psr/event-dispatcher Version ^1
psr/event-dispatcher-implementation Version ^1
psr/log Version ^1 || ^2 || ^3
php-http/discovery Version ^1.11
psr/http-client Version ^1
psr/http-client-implementation Version ^1
psr/http-factory Version ^1
psr/http-factory-implementation Version ^1
psr/http-message Version ^1