diff --git a/.codeclimate.yml b/.codeclimate.yml
deleted file mode 100644
index 24aa1606..00000000
--- a/.codeclimate.yml
+++ /dev/null
@@ -1,5 +0,0 @@
-
-languages:
- PHP: true
-exclude_paths:
- - examples/*
diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml
new file mode 100644
index 00000000..1775e057
--- /dev/null
+++ b/.github/FUNDING.yml
@@ -0,0 +1,3 @@
+# These are supported funding model platforms
+github: [php-tmdb, wtfzdotnet]
+custom: ['https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=SMLZ362KQ8K8W']
diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml
new file mode 100644
index 00000000..8c69385b
--- /dev/null
+++ b/.github/workflows/coding-standards.yml
@@ -0,0 +1,45 @@
+name: "Coding Standards"
+
+on: ["pull_request"]
+
+jobs:
+ coding-standards:
+ name: "Coding Standards"
+ runs-on: "ubuntu-20.04"
+
+ strategy:
+ matrix:
+ php-version:
+ - "7.4"
+
+ steps:
+ - name: "Checkout"
+ uses: "actions/checkout@v2"
+ with:
+ fetch-depth: 10
+
+ - name: "Install PHP"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ coverage: "none"
+ php-version: "${{ matrix.php-version }}"
+ tools: "cs2pr"
+
+ - name: "Cache dependencies installed with Composer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.composer/cache"
+ key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
+ restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
+
+ - name: "Install dependencies with Composer"
+ run: "composer update --no-interaction --no-progress --prefer-dist --prefer-stable"
+
+ - name: "Install git-phpcs"
+ run: "wget https://github.com/diff-sniffer/git/releases/download/0.3.2/git-phpcs.phar"
+
+ - name: "Fetch head branch"
+ run: "git remote set-branches --add origin $GITHUB_BASE_REF && git fetch origin $GITHUB_BASE_REF"
+
+ - name: "Run git-phpcs"
+ run: "php git-phpcs.phar origin/$GITHUB_BASE_REF...$GITHUB_SHA --report=checkstyle | cs2pr"
diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml
new file mode 100644
index 00000000..349b15fd
--- /dev/null
+++ b/.github/workflows/continuous-integration.yml
@@ -0,0 +1,94 @@
+name: "Continuous Integration"
+
+on: ["pull_request", "push"]
+
+env:
+ fail-fast: true
+
+jobs:
+ phpunit:
+ name: "PHPUnit"
+ runs-on: "ubuntu-20.04"
+
+ strategy:
+ matrix:
+ php-version:
+ - "7.4"
+ - "8.0"
+ - "8.1"
+ deps:
+ - "normal"
+ symfony-require:
+ - ""
+ symfony-deprecations-helper:
+ - ""
+ include:
+ - php-version: "7.4"
+ deps: "normal"
+
+ - php-version: "7.4"
+ deps: "low"
+
+ - php-version: "7.4"
+ deps: "dev"
+
+ - php-version: "8.0"
+ deps: "normal"
+
+ - php-version: "8.0"
+ deps: "low"
+
+ - php-version: "8.0"
+ deps: "dev"
+
+ - php-version: "8.1"
+ deps: "normal"
+
+ - php-version: "8.1"
+ deps: "low"
+
+ - php-version: "8.1"
+ deps: "dev"
+
+ steps:
+ - name: "Checkout"
+ uses: "actions/checkout@v2"
+ with:
+ fetch-depth: 2
+
+ - name: "Install PHP with PCOV"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ php-version: "${{ matrix.php-version }}"
+
+ - name: "Cache dependencies installed with composer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.composer/cache"
+ key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}"
+ restore-keys: "php-${{ matrix.php-version }}-composer-locked-"
+
+ - name: "Install stable dependencies with composer"
+ run: "composer update --no-interaction --prefer-dist --prefer-stable"
+ if: "${{ matrix.deps == 'normal' }}"
+
+ - name: "Install dev dependencies with composer"
+ run: "composer update --no-interaction --prefer-dist"
+ if: "${{ matrix.deps == 'dev' }}"
+
+ - name: "Install lowest possible dependencies with composer"
+ run: "composer update --no-interaction --prefer-dist --prefer-stable --prefer-lowest"
+ if: "${{ matrix.deps == 'low' }}"
+
+ - name: "Run PHPUnit"
+ run: "vendor/bin/phpunit --coverage-clover=coverage.xml"
+
+ - name: "Upload coverage file"
+ uses: "actions/upload-artifact@v4"
+ with:
+ name: "phpunit-${{ matrix.php-version }}-${{ matrix.deps }}-${{ hashFiles('composer.lock') }}.coverage"
+ path: "coverage.xml"
+
+ - uses: codecov/codecov-action@v1
+ with:
+ verbose: true
diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml
new file mode 100644
index 00000000..21edc6b6
--- /dev/null
+++ b/.github/workflows/static-analysis.yml
@@ -0,0 +1,34 @@
+name: Static Analysis
+
+on: ["pull_request", "push"]
+
+jobs:
+ static-analysis-phpstan:
+ name: "PHPStan"
+ runs-on: "ubuntu-latest"
+
+ strategy:
+ matrix:
+ php-version:
+ - "7.4"
+ - "8.0"
+ - "8.1"
+
+ steps:
+ - name: "Checkout code"
+ uses: "actions/checkout@v3"
+
+ - name: "Install PHP"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ coverage: "none"
+ php-version: "${{ matrix.php-version }}"
+ tools: cs2pr
+
+ - name: "Install dependencies with Composer"
+ uses: "ramsey/composer-install@v2"
+ with:
+ php_version: "${{ matrix.php-version }}"
+
+ - name: "Run PHPStan"
+ run: "vendor/bin/phpstan analyse --error-format=checkstyle --no-progress | cs2pr"
diff --git a/.gitignore b/.gitignore
index 9f412858..46e2d17d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,15 +1,12 @@
-/bin
-/docs
-/build/*
-!/build/phpunit.xml
-!/build/phpmd.xml
-!/build/phpdox.xml
-/vendor/
-/composer.lock
-/*.php
-/.idea/
-/apikey.php
-/phpunit
-/public_html
-/cache.properties
-/tmdb.log
+.idea/
+cache.properties/
+coverage/
+vendor/
+examples/apikey.php
+composer.lock
+.phpcs-cache
+.phpunit.result.cache
+examples/
+examples/var/
+phpstan.neon$
+.DS_Store
diff --git a/.scrutinizer.yml b/.scrutinizer.yml
deleted file mode 100644
index 2c16b14a..00000000
--- a/.scrutinizer.yml
+++ /dev/null
@@ -1,34 +0,0 @@
-imports:
- - php
-
-tools:
- php_mess_detector: true
- sensiolabs_security_checker: true
- php_code_coverage: true
- php_pdepend: true
- external_code_coverage:
- timeout: 600
- runs: 4
- php_code_sniffer:
- config:
- standard: PSR4
- filter:
- paths: ['src']
- php_loc:
- enabled: true
- excluded_dirs: [vendor, tests]
- php_cpd:
- enabled: true
- excluded_dirs: [vendor, tests]
-
-checks:
- php:
- code_rating: true
- duplication: true
-
-before_commands:
- - 'composer install --dev --prefer-source'
-
-filter:
- paths: [lib/*]
- excluded_paths: [ bin/*, examples/*, vendor/* ]
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 869f3e5c..00000000
--- a/.travis.yml
+++ /dev/null
@@ -1,37 +0,0 @@
-sudo: false
-language: php
-
-php:
- - 7.1
- - nightly
-
-before_script:
- - composer self-update
- - if [ "$SF_EVT_DISPATCHER_VERSION" != "" ]; then composer require --no-update symfony/event-dispatcher:${SF_EVT_DISPATCHER_VERSION}; fi;
- - if [ "$SF_OPT_RESOLVER_VERSION" != "" ]; then composer require --no-update symfony/options-resolver:${SF_OPT_RESOLVER_VERSION}; fi;
- - composer install --no-interaction --prefer-source
-
-script: vendor/bin/phpunit --coverage-text --coverage-clover=coverage.clover --verbose
-
-matrix:
- include:
- - php: 7.1
- env: [SF_EVT_DISPATCHER_VERSION="^4.0", SF_OPT_RESOLVER_VERSION="^4.4"]
-
-
- - php: 7.2
- env: [SF_EVT_DISPATCHER_VERSION="^4.0", SF_OPT_RESOLVER_VERSION="^4.4"]
- - php: 7.2
- env: [SF_EVT_DISPATCHER_VERSION="^5.0", SF_OPT_RESOLVER_VERSION="^5.0"]
-
- - php: 7.3
- env: [SF_EVT_DISPATCHER_VERSION="^5.0", SF_OPT_RESOLVER_VERSION="^5.0"]
-
-
- allow_failures:
- - php: nightly
- fast_finish: true
-
-after_script:
- - wget https://scrutinizer-ci.com/ocular.phar
- - php ocular.phar code-coverage:upload --format=php-clover coverage.clover
diff --git a/README.md b/README.md
index 5434e124..b3f3151f 100644
--- a/README.md
+++ b/README.md
@@ -1,83 +1,111 @@
-# A PHP Wrapper for use with the [TMDB API](http://docs.themoviedb.apiary.io/).
+# A PHP Wrapper for use with the [TMDB API](https://developers.themoviedb.org/4/).
[](https://packagist.org/packages/php-tmdb/api)
-[](https://travis-ci.org/php-tmdb/api)
-[](https://scrutinizer-ci.com/g/php-tmdb/api/?branch=2.1)
-[](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
-
-[](https://packagist.org/packages/php-tmdb/api)
-[](https://packagist.org/packages/php-tmdb/api)
-[](https://www.versioneye.com/user/projects/551fe134971f7847ca000451)
+[](https://github.com/php-tmdb/api/releases)
+[](https://github.com/php-tmdb/api/actions/workflows/continuous-integration.yml)
+[](https://github.com/php-tmdb/api/actions/workflows/coding-standards.yml)
+[](https://codecov.io/gh/php-tmdb/api)
+[](https://packagist.org/packages/php-tmdb/api)
[](https://packagist.org/packages/php-tmdb/api)
-Currently unit tests are run on travis, with the following versions:
+Tests run with minimal, normal and development dependencies.
-- 5.6
-- 7.0
-- 7.1
-- HHVM (failures allowed)
-- nightly (failures allowed)
+## Buy me a coffee, or a beer :-)
-## Features
+
-### Main features
+My stomach will appreciate your donation!
+
+## 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
+## 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](#install-php-tmdbapi),
+and then follow [the quickstart](#new-to-psr-standards-or-composer) 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](https://www.php-fig.org/psr/psr-3/), [jump to section](#logging).
+ - Logs TMDB API exceptions, [jump to section](#tmdbeventlistenerloggerlogapierrorlistener).
+ - Logs PSR-18 client exceptions, [jump to section](#tmdbeventlistenerloggerloghttpmessagelistener).
+ - Logs requests and responses, [jump to section](#tmdbeventlistenerloggerloghttpmessagelistener).
+ - Logs response hydration, [jump to section](#tmdbeventlistenerloggerloghydrationlistener).
+ - Logs caching behavior , [jump to section](#todo).
+- [PSR-6: Caching Interface](https://www.php-fig.org/psr/psr-6/), [jump to section](#caching).
+- [PSR-7: HTTP Message Interface](https://www.php-fig.org/psr/psr-7/)
+ - Requests and responses will be modified via relevant event listeners.
+- _[PSR-12: Extended Coding Style](https://www.php-fig.org/psr/psr-12/)._
+ - 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.
+- [PSR-14: Event Dispatcher](https://www.php-fig.org/psr/psr-7/), [jump to section](#event-dispatching).
+ - Register our listeners and events, we handle the rest.
+- _[PSR-16: Simple Cache](https://www.php-fig.org/psr/psr-16/), by adapting to PSR-6_
+ - Although we do not implement this at the current stage, there are plenty of adapters converting `PSR-16` implementations to `PSR-6`.
+ - We might rework this at a later stage to prevent the extra dependencies that the `php-http/cache-plugin` brings along.
+- [PSR-17: HTTP Factories](https://www.php-fig.org/psr/psr-17/)
+ - Bring along the http factories of your choice.
+- [PSR-18: HTTP Client](https://www.php-fig.org/psr/psr-18/)
+ - Bring along the PSR-18 http client of your choice.
+
+## Framework implementations
+
+- Symfony _(maintained by php-tmdb developers)_
+ - [php-tmdb/symfony](https://github.com/php-tmdb/symfony)
+- Laravel _(community maintained)_
+ - [php-tmdb/laravel](https://github.com/php-tmdb/laravel)
-- 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.
+## Installation
-## Plug-ins
+Install [composer](https://getcomposer.org/download/).
-- Symfony
- - [php-tmdb/symfony](https://github.com/php-tmdb/symfony).
-- Laravel
- - [php-tmdb/laravel](https://github.com/php-tmdb/laravel).
+Before we can install the api library, you need to install a set of dependencies that provide the following implementations.
-## Installation
+## Dependencies you have to fulfill yourself
-Install Composer
+- For `PSR-7: HTTP Message Interface`, for example `nyholm/psr7`.
+- For `PSR-14: Event Dispatcher`, for example `symfony/event-dispatcher`.
+- For `PSR-17: HTTP Factories`, for example `nyholm/psr7`.
+- For `PSR-18: HTTP Client`, for example `guzzlehttp/guzzle`.
-```
-$ 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._
+**I urge you to implement the optional caching implementation**
-Add the following to your require block in `composer.json` config
+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.
-```json
-"php-tmdb/api": "~2.1"
+```shell script
+composer require php-http/cache-plugin:^1.7
```
-__If your new to composer and have no clue what I'm talking about__
+Even though [themoviedb.org](https://www.themoviedb.org/) disabled [rate limiting](https://developers.themoviedb.org/3/getting-started/request-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.
-Just create a file named `composer.json` in your document root:
+- For `PSR-6: Caching Interface`, for example `symfony/cache`.
+- For `PSR-16: Simple Cache`, with an PSR-6 adapter for example `symfony/cache`, then use [the PSR-16 to PSR-6 adapter](https://symfony.com/doc/current/components/cache/psr6_psr16_adapters.html).
-```json
-{
- "require": {
- "php-tmdb/api": "~2.1"
- }
-}
-```
+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.
-Now let's install and pull in the dependencies!
+_Optional dependencies_
-```
-composer install
+- For `PSR-3: Logger Interface`, for example `monolog/monolog`.
+
+## Install php-tmdb/api
+
+If the required dependencies above are met, you are ready to install the library.
+
+```shell script
+composer require php-tmdb/api:^4
```
Include Composer's autoloader:
@@ -86,170 +114,399 @@ 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.
+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;
+
+```shell script
+composer require php-tmdb/api:^4 symfony/event-dispatcher guzzlehttp/guzzle symfony/cache monolog/monolog nyholm/psr7
+```
+
+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](examples/) folder, for example
+[examples/movies/api/get.php](examples/movies/model/get.php) or [examples/movies/api/get.php](examples/movies/api/get.php) files.
## Constructing the Client
-First we always have to construct 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](examples/setup-client.php)
+- [Minimal setup with psr-6 caching](examples/setup-client-cache-psr6.php)
+- [Full setup](examples/setup-client-full.php)
+ - 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](#model-usage)'s functionality up ahead.
```php
-$token = new \Tmdb\ApiToken('your_tmdb_api_key_here');
-$client = new \Tmdb\Client($token);
+use Tmdb\Client;
+
+$client = new Client();
+$movie = $client->getMoviesApi()->getMovie(550);
```
-If you'd like to make unsecure requests (by __default__ we use secure requests).
+If you want to provide any other query arguments.
```php
-$client = new \Tmdb\Client($token, ['secure' => false]);
+use Tmdb\Client;
+
+$client = new Client();
+$movie = $client->getMoviesApi()->getMovie(550, ['language' => 'en']);
```
-Caching is enabled by default, and uses a slow filesystem handler, which you can either:
+For all further calls just review the [unit tests](test/Tmdb/Tests) or [examples](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.
- - Replace the `path` of the storage of, by supplying the option in the client:
+Instead of calling upon the client, you pass the client onto one of the many repositories and do then some work on it.
```php
-$client = new \Tmdb\Client($token, [
- 'cache' => [
- 'path' => '/tmp/php-tmdb'
- ]
-]);
+use Tmdb\Repository\MovieRepository;
+use Tmdb\Client;
+
+$client = new Client();
+$repository = new MovieRepository($client);
+$movie = $repository->load(87421);
+
+echo $movie->getTitle();
```
- - Or replace the whole implementation with another CacheStorage of Doctrine:
+
+__The repositories also contain the other API methods that are available through the API namespace.__
```php
-use Doctrine\Common\Cache\ArrayCache;
+use Tmdb\Repository\MovieRepository;
+use Tmdb\Client;
-$client = new \Tmdb\Client($token, [
- 'cache' => [
- 'handler' => new ArrayCache()
- ]
- ]
-);
+$client = new Client();
+$repository = new MovieRepository($client);
+$topRated = $repository->getTopRated(['page' => 3]);
+// or
+$popular = $repository->getPopular();
```
-_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:
+For all further calls just review the [unit tests](test/Tmdb/Tests) or [examples](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)`.
+
+### 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)`.
+
+### 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.
+- `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;
```php
-$client = new \Tmdb\Client($token, [
- 'cache' => [
- 'enabled' => false
+use Tmdb\Client;
+
+$client = new Client([
+ 'hydration' => [
+ 'event_listener_handles_hydration' => true,
+ 'only_for_specified_models' => [
+ Tmdb\Model\Movie::class
+ ]
]
]);
```
-If you want to add some logging capabilities (requires `monolog/monolog`), defaulting to the filesystem;
+If that configuration has been applied, also make sure the event dispatcher you use is aware of our `HydrationListener`;
```php
-$client = new \Tmdb\Client($token, [
- 'log' => [
- 'enabled' => true,
- 'path' => '/var/www/php-tmdb-api.log'
- ]
-]);
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\HydrationEvent;
+use Tmdb\Event\Listener\HydrationListener;
+
+$eventDispatcher = new EventDispatcher();
+$hydrationListener = new HydrationListener($eventDispatcher);
+$eventDispatcher->addListener(HydrationEvent::class, $hydrationListener);
```
-However during development you might like some console magic like `ChromePHP` or `FirePHP`;
+_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.
+
+## 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`.
```php
-$client = new \Tmdb\Client($token, [
- 'log' => [
- 'enabled' => true,
- 'handler' => new \Monolog\Handler\ChromePHPHandler()
- ]
-]);
+use Symfony\Component\Cache\Adapter\FilesystemAdapter;
+use Tmdb\Event\Listener\Psr6CachedRequestListener;
+use Tmdb\Repository\MovieRepository;
+use Tmdb\Client;
+
+$client = new Client();
+
+$cache = new FilesystemAdapter('php-tmdb', 86400, __DIR__ . '/cache');
+$requestListener = new Psr6CachedRequestListener(
+ $client->getHttpClient(),
+ $client->getEventDispatcher(),
+ $cache,
+ $client->getHttpClient()->getPsr17StreamFactory(),
+ []
+);
+
+$repository = new MovieRepository($client);
+$popular = $repository->getPopular();
```
-## General API Usage
+_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.
-If your looking for a simple array entry point the API namespace is the place to be.
+#### Tmdb\Event\Listener\Logger\LogApiErrorListener
```php
-$movie = $client->getMoviesApi()->getMovie(550);
+use Monolog\Logger;
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\Listener\Logger\LogApiErrorListener;
+use Tmdb\Event\TmdbExceptionEvent;
+use Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter;
+
+$eventDispatcher = new EventDispatcher();
+$apiErrorListener = new LogApiErrorListener(
+ new Logger(),
+ new SimpleTmdbApiExceptionFormatter()
+);
+
+$eventDispatcher->addListener(TmdbExceptionEvent::class, $apiErrorListener);
```
-If you want to provide any other query arguments.
+This will log exceptions thrown when a response has successfully been received, but the response indicated the request was not successful.
+
+```log
+[2021-01-01 13:24:14] php-tmdb.CRITICAL: Critical API exception: 7 Invalid API key: You must be granted a valid key. [] []
+```
+
+#### Tmdb\Event\Listener\Logger\LogHttpMessageListener
```php
-$movie = $client->getMoviesApi()->getMovie(550, array('language' => 'en'));
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\HttpClientExceptionEvent;
+use Tmdb\Event\Listener\Logger\LogHttpMessageListener;
+use Tmdb\Event\ResponseEvent;
+use Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter;
+
+$eventDispatcher = new EventDispatcher();
+$requestLoggerListener = new LogHttpMessageListener(
+ new Monolog\Logger(),
+ new SimpleHttpMessageFormatter()
+);
+
+$eventDispatcher->addListener(BeforeRequestEvent::class, $requestLoggerListener);
+$eventDispatcher->addListener(ResponseEvent::class, $requestLoggerListener);
+$eventDispatcher->addListener(HttpClientExceptionEvent::class, $requestLoggerListener);
```
-## Model Usage
+This will log outgoing requests and responses.
-However the library can also be used in an object oriented manner, which I reckon is the __preferred__ way of doing things.
+```log
+[2021-01-01 13:11:18] php-tmdb.INFO: Sending request: GET https://api.themoviedb.org/3/company/1?include_adult=true&language=en-US®ion=us 1.1 {"length":0,"has_session_token":false} []
+[2021-01-01 13:11:18] php-tmdb.INFO: Received response: 200 OK 1.1 {"status_code":200,"length":223} []
+```
-Instead of calling upon the client, you pass the client onto one of the many repositories and do then some work on it.
+In case of any other PSR-18 client exceptions ( connection errors for example ), these will also be written to the log.
+
+```log
+[2021-01-01 13:36:39] php-tmdb.INFO: Sending request: GET https://api.themoviedb.org/3/company/1?include_adult=true&language=en-US®ion=us 1.1 {"length":0,"has_session_token":false} []
+[2021-01-01 13:36:39] php-tmdb.CRITICAL: Critical http client error: 0 cURL error 7: Failed to connect to api.themoviedb.org port 443: Connection refused (see https://curl.haxx.se/libcurl/c/libcurl-errors.html) {"request":"https://api.themoviedb.org/3/company/1?include_adult=true&language=en-US®ion=us"} []
+```
+
+#### Tmdb\Event\Listener\Logger\LogHydrationListener
```php
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(87421);
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\BeforeHydrationEvent;
+use Tmdb\Event\Listener\Logger\LogHydrationListener;
+use Tmdb\Formatter\Hydration\SimpleHydrationFormatter;
+
+$eventDispatcher = new EventDispatcher();
+$hydrationLoggerListener = new LogHydrationListener(
+ new Monolog\Logger(),
+ new SimpleHydrationFormatter(),
+ false // set to true if you wish to add the json data passed for each hydration, do not use this in production!
+);
-echo $movie->getTitle();
+$eventDispatcher->addListener(BeforeHydrationEvent::class, $hydrationLoggerListener);
```
-__The repositories also contain the other API methods that are available through the API namespace.__
+This will log hydration of models with (optionally) their data, useful for debugging.
+
+```log
+[2021-01-01 13:11:18] php-tmdb.DEBUG: Hydrating model "Tmdb\Model\Image\LogoImage". {"data":{"file_path":"/o86DbpburjxrqAzEDhXZcyE8pDb.png"},"data_size":49} []
+[2021-01-01 13:11:18] php-tmdb.DEBUG: Hydrating model "Tmdb\Model\Company". {"data":{"description":"","headquarters":"San Francisco, California","homepage":"https://www.lucasfilm.com/","id":1,"logo_path":"/o86DbpburjxrqAzEDhXZcyE8pDb.png","name":"Lucasfilm Ltd.","origin_country":"US","parent_company":null},"data_size":227} []
+```
+
+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.
```php
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$topRated = $repository->getTopRated(array('page' => 3));
-// or
-$popular = $repository->getPopular();
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\AdultFilterRequestListener;
+
+$eventDispatcher = new EventDispatcher();
+$adultFilterListener = new AdultFilterRequestListener(true);
+
+$eventDispatcher->addListener(BeforeRequestEvent::class, $adultFilterListener);
```
-## Some other useful hints
+### Language filter
-### Event Dispatching
+To enable filtering contents on language, add the following listener.
-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.
+```php
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\LanguageFilterRequestListener;
+
+$eventDispatcher = new EventDispatcher();
+$languageFilterListener = new LanguageFilterRequestListener('nl-NL');
-See the files for [TmdbEvents](lib/Tmdb/Event/TmdbEvents.php) and [RequestSubscriber](lib/Tmdb/Event/RequestSubscriber.php) respectively.
+$eventDispatcher->addListener(BeforeRequestEvent::class, $languageFilterListener);
+```
-### Image Helper
+### Region filter
-An `ImageHelper` class is provided to take care of the images, which does require the configuration to be loaded:
+To enable filtering contents on region, add the following listener.
```php
-$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
-$config = $configRepository->load();
+use Symfony\Component\EventDispatcher\EventDispatcher;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\RegionFilterRequestListener;
-$imageHelper = new \Tmdb\Helper\ImageHelper($config);
+$eventDispatcher = new EventDispatcher();
+$regionFilterListener = new RegionFilterRequestListener('nl');
-echo $imageHelper->getHtml($image, 'w154', 154, 80);
+$eventDispatcher->addListener(BeforeRequestEvent::class, $regionFilterListener);
```
-### Plug-ins
+## Guest session
-At the moment there are only two useful plug-ins that are not enabled by default, and you might want to use these:
+If you want to make use of guest sessions, you need to specify this explicitly on the client.
```php
-$plugin = new \Tmdb\HttpClient\Plugin\LanguageFilterPlugin('nl');
+use Tmdb\Client;
+use Tmdb\Token\Session\GuestSessionToken;
+
+$client = new Client();
+$client->setGuestSessionToken(new GuestSessionToken('my_token'));
+
+// Now you can make calls in the guest sessions namespace.
```
-_Tries to fetch everything it can in Dutch._
+
+## Image Helper
+
+An `ImageHelper` class is present to take care of the images, which does require the configuration to be loaded:
```php
-$plugin = new \Tmdb\HttpClient\Plugin\AdultFilterPlugin(true);
+use Tmdb\Client;
+use Tmdb\Helper\ImageHelper;
+use Tmdb\Model\Image;
+use Tmdb\Repository\ConfigurationRepository;
+
+$client = new Client();
+$image = new Image();
+$configRepository = new ConfigurationRepository($client);
+$config = $configRepository->load();
+
+$imageHelper = new ImageHelper($config);
+
+echo $imageHelper->getHtml($image, 'w154', 154, 80);
```
-_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:
```php
+use Tmdb\Model\Movie;
+use Tmdb\Model\Image\PosterImage;
+
+$movie = new Movie();
+
foreach($movie->getImages()->filter(
function($key, $value){
- if ($value instanceof \Tmdb\Model\Image\PosterImage) { return true; }
+ return $value instanceof PosterImage;
}
) as $image) {
-
- // do something with all poster images
+ // do something with all poster images
}
```
These basic filters however are already covered in the `Images` collection object:
```php
+use Tmdb\Model\Movie;
+
+/** @var $movie Movie **/
$backdrop = $movie
->getImages()
->filterBackdrops()
@@ -257,17 +514,7 @@ $backdrop = $movie
```
_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.
+### The GenericCollection and the ResultCollection
-## 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 ;))!
-
-
+- 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 pagination.
diff --git a/UPGRADE-3.0.md b/UPGRADE-3.0.md
new file mode 100644
index 00000000..fc54233d
--- /dev/null
+++ b/UPGRADE-3.0.md
@@ -0,0 +1,4 @@
+Upgrading to 3.0
+----------------
+
+This was just a release in between to get the symfony 5 dependency going.
diff --git a/UPGRADE-4.0.md b/UPGRADE-4.0.md
new file mode 100644
index 00000000..b9bc552f
--- /dev/null
+++ b/UPGRADE-4.0.md
@@ -0,0 +1,88 @@
+Upgrading to 4.0
+----------------
+
+4.0 brings a massive refreshment to this library, and thus the upgrade path involves a little more than you have
+been used to in the past.
+
+**Important**
+
+- I've decided to drop anything below PHP 7.3, even though at this point security fixes have support for 7.2, we consider 7.2 EOL.
+- During the modifications I've tried my best to maintain as many backwards compatibility in mind as possible, but as you
+could expect with a major version; things might break on your end.
+
+**This update involves**
+
+- (Re-Implementation) of PSR-3
+- Implementation of PSR-7
+- Implementation of PSR-12
+- Implementation of PSR-14
+- Implementation of PSR-16
+- Implementation of PSR-17
+- Implementation of PSR-18
+- Cleanup of tests
+- Dropping doctrine cache ( bring your own PSR-16 client )
+- Dropping guzzle http ( bring your own PSR-18 client )
+- New CI/CD integration ( github actions, as travis-ci is being abandoned )
+ - Code style checking
+ - Unit tests running on PHP 7.3, 7.4 and 8.0 ( still allowing failures as of now )
+
+The good news
+=============
+
+Just to give you a little sense of relief, besides adding the necessary type hints, the user API for the `Tmdb/Api` calls and `Tmdb/Repository` namespaces will **not** change.
+If you have custom API classes or Repository classes these will need to be adjusted.
+
+Plugins were really just event listeners
+----------------------------------------
+
+Review the new listeners in `lib/Tmdb/Event/Listener`, if you made use of an extra plugin before,
+they were moved here and renamed.
+
+With this release also the new `Tmdb/Event/Listener/RegionFilterRequestListener` was introduced.
+
+@todo since library isn't fully done, can't write much yet about PSR-14
+
+Request and Responses
+---------------------
+
+The base request and response classes internally are gone, as well as the adapter interfacing that was present.
+
+Where you used to be able to rely on an internal library request / response within events, you will now have to
+modify your code to adhere to PSR-7. The internals now also rely on an PSR-18 client to be provided,
+ the http factories from PSR-17 and request and response messages according to PSR-7.
+
+Registering the event listeners ( yourself )
+--------------------------------------------
+
+_we could create a callback function the user gives, and call that to register each listener?_
+
+- ExampleEvent::class => new ExampleListener($deps)
+
+Hydration Events
+----------------
+
+The hydration events caused a significant overhead, as such it has been disabled by default.
+
+To re-enable this functionality, we recommend only using it for models you need to modify data for;
+
+```php
+$client = new \Tmdb\Client([
+ 'hydration' => [
+ 'event_listener_handles_hydration' => true,
+ 'only_for_specified_models' => [
+ Tmdb\Model\Movie::class
+ ]
+ ]
+]);
+```
+
+If that configuration has been applied, also make sure the event dispatcher you use is aware of our `HydrationListener`;
+
+```php
+// Or any other PSR-14 compliant Event Dispatcher
+$eventDispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher();
+$hydrationListener = new \Tmdb\Event\Listener\HydrationListener($eventDispatcher);
+$eventDispatcher->addListener(\Tmdb\Event\HydrationEvent::class, $hydrationListener);
+```
+
+_If you re-enable this functionality without specifying any models, all hydration will be done through the event listeners._
diff --git a/apikey.php.dist b/apikey.php.dist
deleted file mode 100644
index 35f2201f..00000000
--- a/apikey.php.dist
+++ /dev/null
@@ -1,12 +0,0 @@
-=7.1.3",
- "ext-curl": "*",
- "symfony/event-dispatcher": ">=4.4,<6",
- "symfony/options-resolver": ">=4.4,<6",
- "guzzlehttp/guzzle": "~6.0",
- "psr/log": "~1.0",
- "doctrine/cache": "^1.6",
- "kevinrob/guzzle-cache-middleware": "^1.2 || ^2.0",
- "rtheunissen/guzzle-log-middleware": "^0.4.0"
+ "php": "^7.3 || ^8.0",
+ "ext-json": "*",
+ "symfony/options-resolver": "^4.4 || ^5 || ^6",
+ "psr/cache": "^1 || ^2 || ^3",
+ "psr/simple-cache": "^1 || ^2 || ^3",
+ "psr/event-dispatcher": "^1",
+ "psr/event-dispatcher-implementation": "^1",
+ "psr/log": "^1 || ^2 || ^3",
+ "php-http/discovery": "^1.11",
+ "psr/http-client": "^1",
+ "psr/http-client-implementation": "^1",
+ "psr/http-factory": "^1",
+ "psr/http-factory-implementation": "^1",
+ "psr/http-message": "^1"
},
"require-dev": {
- "phpunit/phpunit": "^5.0",
- "monolog/monolog": ">=1.11.0"
+ "nyholm/psr7": "^1.2",
+ "php-http/mock-client": "^1.2",
+ "slevomat/coding-standard": "^8.8",
+ "squizlabs/php_codesniffer": "^3.5.8",
+ "symfony/cache": "^4.4 || ^5 || ^6",
+ "symfony/event-dispatcher": "^4.4 || ^5 || ^6",
+ "phpstan/phpstan": "^1.8.1",
+ "phpstan/phpstan-deprecation-rules": "^1.1",
+ "spaze/phpstan-disallowed-calls": "^2.11",
+ "phpunit/phpunit": "^9.6.3",
+ "php-http/guzzle7-adapter": "^1.0",
+ "monolog/monolog": "^2.9.1 || ^3.0",
+ "php-http/cache-plugin": "^1.7",
+ "jeroen/psr-log-test-doubles": "^2.1 || ^3"
},
- "suggest": {
- "monolog/monolog": "Required if you want to make use of logging features."
+ "scripts": {
+ "test": "vendor/bin/phpunit",
+ "test-ci": "vendor/bin/phpunit --coverage-text --coverage-clover=build/coverage.xml coverage",
+ "test-coverage": "php -d xdebug.mode=coverage vendor/bin/phpunit --coverage-html build/coverage",
+ "test-cs": "vendor/bin/phpcs",
+ "test-phpstan": "vendor/bin/phpstan analyse"
},
- "autoload": {
- "psr-4": { "Tmdb\\": "lib/Tmdb" }
+ "suggest": {
+ "psr/log-implementation": "If you wish to enable logging features, provide an PSR-3 logger.",
+ "monolog/monolog": "Great logger to use, but you can pick any PSR-3 logger you wish.",
+ "psr/cache-implementation": "If you wish to enable caching features, provide an PSR-6 cache implementation.",
+ "symfony/cache": "Great cache to use, but you can pick any PSR-6 cache you wish.",
+ "php-http/cache-plugin": "When making use of cache, you need to install this plugin.",
+ "psr/simple-cache-implementation": "If you wish to enable caching features, provide an PSR-16 cache."
},
- "extra": {
- "branch-alias": {
- "dev-master": "2.1-dev"
+ "type": "library",
+ "config": {
+ "allow-plugins": {
+ "dealerdirect/phpcodesniffer-composer-installer": true,
+ "php-http/discovery": false
}
}
}
diff --git a/examples/account/api/account.php b/examples/account/api/account.php
index 42fe39a5..25fe6698 100644
--- a/examples/account/api/account.php
+++ b/examples/account/api/account.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$account = $client->getAccountApi()->getAccount();
diff --git a/examples/account/api/favorite.php b/examples/account/api/favorite.php
index f514b4a8..3e07212a 100644
--- a/examples/account/api/favorite.php
+++ b/examples/account/api/favorite.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$favorite = $client->getAccountApi()->favorite(TMDB_ACCOUNT_ID, 550, true);
diff --git a/examples/account/api/favorite_movies.php b/examples/account/api/favorite_movies.php
index 77c4eba2..7e6b8fd7 100644
--- a/examples/account/api/favorite_movies.php
+++ b/examples/account/api/favorite_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$favorite_movies = $client->getAccountApi()->getFavoriteMovies(TMDB_ACCOUNT_ID);
diff --git a/examples/account/api/lists.php b/examples/account/api/lists.php
index 00beab4e..8c436f58 100644
--- a/examples/account/api/lists.php
+++ b/examples/account/api/lists.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$lists = $client->getAccountApi()->getLists(TMDB_ACCOUNT_ID);
diff --git a/examples/account/api/rated_movies.php b/examples/account/api/rated_movies.php
index 61b2c8dd..49bea8ef 100644
--- a/examples/account/api/rated_movies.php
+++ b/examples/account/api/rated_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$rated_movies = $client->getAccountApi()->getRatedMovies(TMDB_ACCOUNT_ID);
diff --git a/examples/account/api/watchlist.php b/examples/account/api/watchlist.php
index 1147fdd6..b0f9cf10 100644
--- a/examples/account/api/watchlist.php
+++ b/examples/account/api/watchlist.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$watchlist = $client->getAccountApi()->watchlist(TMDB_ACCOUNT_ID, 97020, true);
diff --git a/examples/account/api/watchlist_movies.php b/examples/account/api/watchlist_movies.php
index 6728c41c..23bb1231 100644
--- a/examples/account/api/watchlist_movies.php
+++ b/examples/account/api/watchlist_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$watchlist_movies = $client->getAccountApi()->getMovieWatchlist(TMDB_ACCOUNT_ID);
diff --git a/examples/account/model/account.php b/examples/account/model/account.php
index 35365e74..35a36c3c 100644
--- a/examples/account/model/account.php
+++ b/examples/account/model/account.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
-$account = $accountRepository->getAccount();
+$accountRepository = new AccountRepository($client);
+$account = $accountRepository->getAccount();
var_dump($account);
diff --git a/examples/account/model/favorite_movie.php b/examples/account/model/favorite_movie.php
index 253b6c35..b4d39b53 100644
--- a/examples/account/model/favorite_movie.php
+++ b/examples/account/model/favorite_movie.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getFavoriteMovies(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/favorite_movie_add.php b/examples/account/model/favorite_movie_add.php
index 127792d2..24e8134f 100644
--- a/examples/account/model/favorite_movie_add.php
+++ b/examples/account/model/favorite_movie_add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->favorite(TMDB_ACCOUNT_ID, 150);
var_dump($lists);
diff --git a/examples/account/model/favorite_tv.php b/examples/account/model/favorite_tv.php
index 4a7c623f..22040d02 100644
--- a/examples/account/model/favorite_tv.php
+++ b/examples/account/model/favorite_tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getFavoriteTvShows(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/favorite_tv_add.php b/examples/account/model/favorite_tv_add.php
index a75161c0..3f7186db 100644
--- a/examples/account/model/favorite_tv_add.php
+++ b/examples/account/model/favorite_tv_add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->favorite(TMDB_ACCOUNT_ID, 1973, true, 'tv');
var_dump($lists);
diff --git a/examples/account/model/lists.php b/examples/account/model/lists.php
index 0a69b4ec..e7dcd160 100644
--- a/examples/account/model/lists.php
+++ b/examples/account/model/lists.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+use Tmdb\Token\Session\SessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getLists(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/rated_movies.php b/examples/account/model/rated_movies.php
index ccb29ab4..71f06edc 100644
--- a/examples/account/model/rated_movies.php
+++ b/examples/account/model/rated_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client-full.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getRatedMovies(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/rated_tv.php b/examples/account/model/rated_tv.php
index 8d698178..16bf18a2 100644
--- a/examples/account/model/rated_tv.php
+++ b/examples/account/model/rated_tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getRatedTvShows(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/watchlist_movie.php b/examples/account/model/watchlist_movie.php
index e6fc388e..8b5be5bb 100644
--- a/examples/account/model/watchlist_movie.php
+++ b/examples/account/model/watchlist_movie.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getMovieWatchlist(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/watchlist_movie_add.php b/examples/account/model/watchlist_movie_add.php
index 1064c387..8209e9e1 100644
--- a/examples/account/model/watchlist_movie_add.php
+++ b/examples/account/model/watchlist_movie_add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->watchlist(TMDB_ACCOUNT_ID, 49047);
var_dump($lists);
diff --git a/examples/account/model/watchlist_tv.php b/examples/account/model/watchlist_tv.php
index 6863d73e..ded1af66 100644
--- a/examples/account/model/watchlist_tv.php
+++ b/examples/account/model/watchlist_tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->getTvWatchlist(TMDB_ACCOUNT_ID);
var_dump($lists);
diff --git a/examples/account/model/watchlist_tv_add.php b/examples/account/model/watchlist_tv_add.php
index c1dce300..d85db7dc 100644
--- a/examples/account/model/watchlist_tv_add.php
+++ b/examples/account/model/watchlist_tv_add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Client;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\AccountRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
/**
- * @var \Tmdb\Repository\AccountRepository $accountRepository
+ * @var AccountRepository $accountRepository
*/
-$accountRepository = new \Tmdb\Repository\AccountRepository($client);
+$accountRepository = new AccountRepository($client);
$lists = $accountRepository->watchlist(TMDB_ACCOUNT_ID, 1973, true, 'tv');
var_dump($lists);
diff --git a/examples/apikey.php.dist b/examples/apikey.php.dist
new file mode 100644
index 00000000..d25b2146
--- /dev/null
+++ b/examples/apikey.php.dist
@@ -0,0 +1,23 @@
+
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\RequestToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client-full.php.php');
+$token = new ApiToken(TMDB_API_KEY);
-$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN);
+$requestToken = new RequestToken(TMDB_REQUEST_TOKEN);
$client->getAuthenticationApi()->authenticateRequestToken($requestToken->getToken());
diff --git a/examples/authentication/api/get-guest-session.php b/examples/authentication/api/get-guest-session.php
index 1e88bcc4..424cb84d 100644
--- a/examples/authentication/api/get-guest-session.php
+++ b/examples/authentication/api/get-guest-session.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Token\Api\ApiToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
+
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
$sessionToken = $client->getAuthenticationApi()->getNewGuestSession();
diff --git a/examples/authentication/api/get-session.php b/examples/authentication/api/get-session.php
index d3a23626..46ea1c1c 100644
--- a/examples/authentication/api/get-session.php
+++ b/examples/authentication/api/get-session.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Session\RequestToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
+
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$token = new ApiToken(TMDB_API_KEY);
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN);
+$requestToken = new RequestToken(TMDB_REQUEST_TOKEN);
$sessionToken = $client->getAuthenticationApi()->getNewSession($requestToken->getToken());
diff --git a/examples/authentication/api/get-token.php b/examples/authentication/api/get-token.php
index 6d9a8065..173e5100 100644
--- a/examples/authentication/api/get-token.php
+++ b/examples/authentication/api/get-token.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
$requestToken = $client->getAuthenticationApi()->getNewToken();
var_dump($requestToken);
diff --git a/examples/authentication/api/session_token_with_username_and_password.php b/examples/authentication/api/session_token_with_username_and_password.php
index dd073408..946c4e18 100644
--- a/examples/authentication/api/session_token_with_username_and_password.php
+++ b/examples/authentication/api/session_token_with_username_and_password.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Token\Session\RequestToken;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$requestToken = new RequestToken(TMDB_REQUEST_TOKEN);
$validatedRequestToken = $client->getAuthenticationApi()->validateRequestTokenWithLogin(
$requestToken,
diff --git a/examples/authentication/model/authenticate_request_token.php b/examples/authentication/model/authenticate_request_token.php
index de971160..25d35953 100644
--- a/examples/authentication/model/authenticate_request_token.php
+++ b/examples/authentication/model/authenticate_request_token.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\AuthenticationRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client);
-$requestToken = $authenticationRepository->getRequestToken();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$authenticationRepository = new AuthenticationRepository($client);
+$requestToken = $authenticationRepository->getRequestToken();
// Will force a redirect
$authenticationRepository->authenticateRequestToken($requestToken);
diff --git a/examples/authentication/model/guest_session_token.php b/examples/authentication/model/guest_session_token.php
index 05074cc4..072af6d0 100644
--- a/examples/authentication/model/guest_session_token.php
+++ b/examples/authentication/model/guest_session_token.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\AuthenticationRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client);
-$sessionToken = $authenticationRepository->getGuestSessionToken($requestToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$authenticationRepository = new AuthenticationRepository($client);
+$sessionToken = $authenticationRepository->getGuestSessionToken();
var_dump($sessionToken);
diff --git a/examples/authentication/model/request_token.php b/examples/authentication/model/request_token.php
index ff706eec..e29be04b 100644
--- a/examples/authentication/model/request_token.php
+++ b/examples/authentication/model/request_token.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\AuthenticationRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client);
-$requestToken = $authenticationRepository->getRequestToken();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$authenticationRepository = new AuthenticationRepository($client);
+$requestToken = $authenticationRepository->getRequestToken();
var_dump($requestToken);
diff --git a/examples/authentication/model/session_token.php b/examples/authentication/model/session_token.php
index 8a68dbdb..423f0e6c 100644
--- a/examples/authentication/model/session_token.php
+++ b/examples/authentication/model/session_token.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\AuthenticationRepository;
+use Tmdb\Token\Session\RequestToken;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$requestToken = new \Tmdb\RequestToken('2e57316025d7e4df5cfff81f0596209c2465a8bd');
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$requestToken = new RequestToken(TMDB_REQUEST_TOKEN);
-$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client);
-$sessionToken = $authenticationRepository->getSessionToken($requestToken);
+$authenticationRepository = new AuthenticationRepository($client);
+$sessionToken = $authenticationRepository->getSessionToken($requestToken);
var_dump($sessionToken);
diff --git a/examples/authentication/model/session_token_with_username_and_password.php b/examples/authentication/model/session_token_with_username_and_password.php
index 6ca5b3c8..48b37ea4 100644
--- a/examples/authentication/model/session_token_with_username_and_password.php
+++ b/examples/authentication/model/session_token_with_username_and_password.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\AuthenticationRepository;
+use Tmdb\Token\Session\RequestToken;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$requestToken = new \Tmdb\RequestToken(TMDB_REQUEST_TOKEN);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$requestToken = new RequestToken(TMDB_REQUEST_TOKEN);
-$authenticationRepository = new \Tmdb\Repository\AuthenticationRepository($client);
+$authenticationRepository = new AuthenticationRepository($client);
$sessionToken = $authenticationRepository->getSessionTokenWithLogin(
$requestToken,
diff --git a/examples/caching.php b/examples/caching.php
index 0d964be4..d7a9e520 100644
--- a/examples/caching.php
+++ b/examples/caching.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../vendor/autoload.php';
-require_once '../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
+use Tmdb\Client;
+use Tmdb\Repository\MovieRepository;
-// Caching is enabled by default, and makes use of your sys_get_temp_dir()
-// If you'd like to disable it or change the path:
-
-//$client = new \Tmdb\Client($token, null, true, [
-// 'cache' => ['enabled' => false]
-//]);
+require_once '../vendor/autoload.php';
+require_once 'apikey.php';
-$client = new \Tmdb\Client($token, [
- 'cache' => [
- 'enabled' => true,
- 'handler' => new Doctrine\Common\Cache\FilesystemCache(sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'my-cache-path')
- ]
-]);
+/** @var Client $client **/
+$client = require_once('setup-client-cache-psr6.php');
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(19995);
+$repository = new MovieRepository($client);
+$movie = $repository->load(19995);
var_dump($movie);
+exit;
diff --git a/examples/certifications/api/movies.php b/examples/certifications/api/movies.php
index 6990759e..36393cd6 100644
--- a/examples/certifications/api/movies.php
+++ b/examples/certifications/api/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credit = $client->getCertificationsApi()->getMovieList();
var_dump($credit);
diff --git a/examples/certifications/api/tv.php b/examples/certifications/api/tv.php
index 8fbce27d..a70d62fe 100644
--- a/examples/certifications/api/tv.php
+++ b/examples/certifications/api/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credit = $client->getCertificationsApi()->getTvList();
var_dump($credit);
diff --git a/examples/certifications/model/movies.php b/examples/certifications/model/movies.php
index ec98645b..16ceea53 100644
--- a/examples/certifications/model/movies.php
+++ b/examples/certifications/model/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$certificationRepository = new \Tmdb\Repository\CertificationRepository($client);
$certificationList = $certificationRepository->getMovieList();
diff --git a/examples/certifications/model/tv.php b/examples/certifications/model/tv.php
index 63aad850..ff58a4b6 100644
--- a/examples/certifications/model/tv.php
+++ b/examples/certifications/model/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$certificationRepository = new \Tmdb\Repository\CertificationRepository($client);
$certificationList = $certificationRepository->getTvList();
diff --git a/examples/changes/api/movies.php b/examples/changes/api/movies.php
index 05d9a0e1..d73aa80c 100644
--- a/examples/changes/api/movies.php
+++ b/examples/changes/api/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$movieChanges = $client->getChangesApi()->getMovieChanges([
- 'page' => 1,
- 'start_date' => '2014-01-01',
- 'end_date' => '2014-01-02'
-]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$movieChanges = $client->getChangesApi()->getMovieChanges(
+ [
+ 'page' => 1,
+ 'start_date' => '2014-01-01',
+ 'end_date' => '2014-01-02'
+ ]
+);
var_dump($movieChanges);
diff --git a/examples/changes/api/people.php b/examples/changes/api/people.php
index 70b0f4bc..9502b52b 100644
--- a/examples/changes/api/people.php
+++ b/examples/changes/api/people.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$personChanges = $client->getChangesApi()->getPersonChanges([
- 'page' => 1,
- 'start_date' => '2014-01-14',
- 'end_date' => '2014-01-21'
-]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$personChanges = $client->getChangesApi()->getPersonChanges(
+ [
+ 'page' => 1,
+ 'start_date' => '2014-01-14',
+ 'end_date' => '2014-01-21'
+ ]
+);
var_dump($personChanges);
diff --git a/examples/changes/api/tv.php b/examples/changes/api/tv.php
index a6e74924..73b0efe8 100644
--- a/examples/changes/api/tv.php
+++ b/examples/changes/api/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$tvChanges = $client->getChangesApi()->getTvChanges([
- 'page' => 1,
- 'start_date' => '2014-01-14',
- 'end_date' => '2014-01-21'
-]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$tvChanges = $client->getChangesApi()->getTvChanges(
+ [
+ 'page' => 1,
+ 'start_date' => '2014-01-14',
+ 'end_date' => '2014-01-21'
+ ]
+);
var_dump($tvChanges);
diff --git a/examples/changes/model/movies.php b/examples/changes/model/movies.php
index c01b52be..f5239764 100644
--- a/examples/changes/model/movies.php
+++ b/examples/changes/model/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Query\ChangesQuery;
+use Tmdb\Repository\ChangesRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Query\ChangesQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new ChangesQuery();
-$from = new \DateTime('01-01-2014');
-$to = new \DateTime('02-01-2014');
+$from = new DateTime('01-01-2014');
+$to = new DateTime('02-01-2014');
$query
->page(1)
->from($from)
- ->to($to)
-;
+ ->to($to);
-$repository = new \Tmdb\Repository\ChangesRepository($client);
+$repository = new ChangesRepository($client);
$response = $repository->getMovieChanges($query);
var_dump($response);
diff --git a/examples/changes/model/people.php b/examples/changes/model/people.php
index 2778e00d..a21de9e3 100644
--- a/examples/changes/model/people.php
+++ b/examples/changes/model/people.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Query\ChangesQuery;
+use Tmdb\Repository\ChangesRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Query\ChangesQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new ChangesQuery();
-$from = new \DateTime('14-01-2014');
-$to = new \DateTime('21-01-2014');
+$from = new DateTime('14-01-2014');
+$to = new DateTime('21-01-2014');
$query
->page(1)
->from($from)
- ->to($to)
-;
+ ->to($to);
-$repository = new \Tmdb\Repository\ChangesRepository($client);
+$repository = new ChangesRepository($client);
$response = $repository->getPeopleChanges($query);
var_dump($response);
diff --git a/examples/changes/model/tv.php b/examples/changes/model/tv.php
index 095da352..83e87071 100644
--- a/examples/changes/model/tv.php
+++ b/examples/changes/model/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Query\ChangesQuery;
+use Tmdb\Repository\ChangesRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Query\ChangesQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new ChangesQuery();
-$from = new \DateTime('14-01-2014');
-$to = new \DateTime('21-01-2014');
+$from = new DateTime('14-01-2014');
+$to = new DateTime('21-01-2014');
$query
->page(1)
->from($from)
- ->to($to)
-;
+ ->to($to);
-$repository = new \Tmdb\Repository\ChangesRepository($client);
+$repository = new ChangesRepository($client);
$response = $repository->getTvChanges($query);
var_dump($response);
diff --git a/examples/collection/api/get.php b/examples/collection/api/get.php
index e5efded6..dd850f39 100644
--- a/examples/collection/api/get.php
+++ b/examples/collection/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$collection = $client->getCollectionsApi()->getCollection(10);
var_dump($collection);
diff --git a/examples/collection/api/images.php b/examples/collection/api/images.php
index 73a8c860..45d52ef4 100644
--- a/examples/collection/api/images.php
+++ b/examples/collection/api/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$collection = $client->getCollectionsApi()->getImages(10);
var_dump($collection);
diff --git a/examples/collection/model/all.php b/examples/collection/model/all.php
index 210740fd..21e848e1 100644
--- a/examples/collection/model/all.php
+++ b/examples/collection/model/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\CollectionRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\CollectionRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new CollectionRepository($client);
$collection = $repository->load(10);
var_dump($collection);
diff --git a/examples/collection/model/images.php b/examples/collection/model/images.php
index 210740fd..21e848e1 100644
--- a/examples/collection/model/images.php
+++ b/examples/collection/model/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\CollectionRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\CollectionRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new CollectionRepository($client);
$collection = $repository->load(10);
var_dump($collection);
diff --git a/examples/companies/api/get.php b/examples/companies/api/get.php
index fc284edc..a1f2ca7f 100644
--- a/examples/companies/api/get.php
+++ b/examples/companies/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$company = $client->getCompaniesApi()->getCompany(1);
var_dump($company);
diff --git a/examples/companies/api/get_movies.php b/examples/companies/api/get_movies.php
index 1f15c7d2..76feb693 100644
--- a/examples/companies/api/get_movies.php
+++ b/examples/companies/api/get_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$companyMovies = $client->getCompaniesApi()->getMovies(1);
var_dump($companyMovies);
diff --git a/examples/companies/model/get.php b/examples/companies/model/get.php
index e542c2ae..bf51622e 100644
--- a/examples/companies/model/get.php
+++ b/examples/companies/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\CompanyRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\CompanyRepository($client);
-$company = $repository->load(1);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new CompanyRepository($client);
+$company = $repository->load(1);
var_dump($company);
diff --git a/examples/companies/model/get_movies.php b/examples/companies/model/get_movies.php
index fd48e27d..af42cd53 100644
--- a/examples/companies/model/get_movies.php
+++ b/examples/companies/model/get_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\CompanyRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\CompanyRepository($client);
-$companyMovies = $repository->getMovies(1);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new CompanyRepository($client);
+$companyMovies = $repository->getMovies(1);
var_dump($companyMovies);
diff --git a/examples/configuration/api/get.php b/examples/configuration/api/get.php
index 0defceee..c5c37dfe 100644
--- a/examples/configuration/api/get.php
+++ b/examples/configuration/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
header('Content-Type: text/html; charset=utf-8');
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$configuration = $client->getConfigurationApi()->getConfiguration();
var_dump($configuration);
diff --git a/examples/configuration/model/get.php b/examples/configuration/model/get.php
index 98009355..ff05424f 100644
--- a/examples/configuration/model/get.php
+++ b/examples/configuration/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Repository\ConfigurationRepository;
+
header('Content-Type: text/html; charset=utf-8');
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../apikey.php';
-$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$configRepository = new ConfigurationRepository($client);
$config = $configRepository->load();
var_dump($config);
diff --git a/examples/credits/api/get.php b/examples/credits/api/get.php
index a84e445d..279e0228 100644
--- a/examples/credits/api/get.php
+++ b/examples/credits/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credit = $client->getCreditsApi()->getCredit('52542282760ee313280017f9');
var_dump($credit);
diff --git a/examples/credits/model/get.php b/examples/credits/model/get.php
index f1a1ddfc..0d7efd74 100644
--- a/examples/credits/model/get.php
+++ b/examples/credits/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\CreditsRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\CreditsRepository($client);
-$credits = $repository->load('52542282760ee313280017f9');
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new CreditsRepository($client);
+$credits = $repository->load('52542282760ee313280017f9');
var_dump($credits);
diff --git a/examples/discover/api/movies.php b/examples/discover/api/movies.php
index dfea86b0..cc6e54fa 100644
--- a/examples/discover/api/movies.php
+++ b/examples/discover/api/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$response = $client->getDiscoverApi()->discoverMovies([
- 'page' => 1,
- 'language' => 'en'
-]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$response = $client->getDiscoverApi()->discoverMovies(
+ [
+ 'page' => 1,
+ 'language' => 'en'
+ ]
+);
var_dump($response);
diff --git a/examples/discover/api/tv.php b/examples/discover/api/tv.php
index 53afc27c..6213cca0 100644
--- a/examples/discover/api/tv.php
+++ b/examples/discover/api/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$response = $client->getDiscoverApi()->discoverTv([
- 'page' => 1,
- 'language' => 'en'
-]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$response = $client->getDiscoverApi()->discoverTv(
+ [
+ 'page' => 1,
+ 'language' => 'en'
+ ]
+);
var_dump($response);
diff --git a/examples/discover/model/movies.php b/examples/discover/model/movies.php
index 97a21179..5f897005 100644
--- a/examples/discover/model/movies.php
+++ b/examples/discover/model/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Query\Discover\DiscoverMoviesQuery;
+use Tmdb\Repository\DiscoverRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Query\Discover\DiscoverMoviesQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new DiscoverMoviesQuery();
$query
->page(1)
- ->language('en')
-;
+ ->language('en');
-$repository = new \Tmdb\Repository\DiscoverRepository($client);
+$repository = new DiscoverRepository($client);
$response = $repository->discoverMovies($query);
var_dump($response);
diff --git a/examples/discover/model/tv.php b/examples/discover/model/tv.php
index 0942e10a..1a4cab99 100644
--- a/examples/discover/model/tv.php
+++ b/examples/discover/model/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Query\Discover\DiscoverTvQuery;
+use Tmdb\Repository\DiscoverRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Query\Discover\DiscoverTvQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new DiscoverTvQuery();
$query
->page(1)
- ->language('en')
-;
+ ->language('en');
-$repository = new \Tmdb\Repository\DiscoverRepository($client);
+$repository = new DiscoverRepository($client);
$response = $repository->discoverTv($query);
var_dump($response);
diff --git a/examples/exception_handling.php b/examples/exception_handling.php
index cc0ba6ee..cb8b6e78 100644
--- a/examples/exception_handling.php
+++ b/examples/exception_handling.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
header('Content-Type: text/html; charset=utf-8');
use Tmdb\Repository\MovieRepository;
use Tmdb\Exception\TmdbApiException;
require_once '../vendor/autoload.php';
-require_once '../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once 'apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('setup-client.php');
$repository = new MovieRepository($client);
/**
@@ -31,7 +32,8 @@
} catch (TmdbApiException $e) {
if (TmdbApiException::STATUS_RESOURCE_NOT_FOUND == $e->getCode()) {
// not found
- echo '404';exit;
+ echo $e->getMessage();
+ exit;
}
// catch other tmdb specific errors
diff --git a/examples/find/api/get.php b/examples/find/api/get.php
index 4d68a6c8..7fc40e1f 100644
--- a/examples/find/api/get.php
+++ b/examples/find/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$find = $client->getFindApi()->findBy('tt0120737', [
- 'external_source' => 'imdb_id'
-]);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$find = $client->getFindApi()->findBy(
+ 'tt0120737',
+ [
+ 'external_source' => 'imdb_id'
+ ]
+);
var_dump($find);
diff --git a/examples/find/model/get.php b/examples/find/model/get.php
index c91ff339..4051c354 100644
--- a/examples/find/model/get.php
+++ b/examples/find/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\FindRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\FindRepository($client);
-$find = $repository->findBy('tt0120737', ['external_source' => 'imdb_id']);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$repository = new FindRepository($client);
+$find = $repository->findBy('tt0120737', ['external_source' => 'imdb_id']);
var_dump($find);
diff --git a/examples/genres/api/all.php b/examples/genres/api/all.php
index 153321f4..cfe9cfc7 100644
--- a/examples/genres/api/all.php
+++ b/examples/genres/api/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$genres = $client->getGenresApi()->getGenres();
var_dump($genres);
diff --git a/examples/genres/api/allmovies.php b/examples/genres/api/allmovies.php
index 81bca781..31dba57b 100644
--- a/examples/genres/api/allmovies.php
+++ b/examples/genres/api/allmovies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$genres = $client->getGenresApi()->getMovieGenres();
var_dump($genres);
diff --git a/examples/genres/api/alltv.php b/examples/genres/api/alltv.php
index d6f0c3f4..3f0cb811 100644
--- a/examples/genres/api/alltv.php
+++ b/examples/genres/api/alltv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$genres = $client->getGenresApi()->getTvGenres();
var_dump($genres);
diff --git a/examples/genres/api/get.php b/examples/genres/api/get.php
index 293d346c..7f0594f5 100644
--- a/examples/genres/api/get.php
+++ b/examples/genres/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$genre = $client->getGenresApi()->getGenre(28);
var_dump($genre);
diff --git a/examples/genres/api/movies.php b/examples/genres/api/movies.php
index 01202296..6cd10c29 100644
--- a/examples/genres/api/movies.php
+++ b/examples/genres/api/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$genres = $client->getGenresApi()->getMovies(18);
var_dump($genres);
diff --git a/examples/genres/model/all.php b/examples/genres/model/all.php
index 1378e308..0611b0b7 100644
--- a/examples/genres/model/all.php
+++ b/examples/genres/model/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\GenreRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\GenreRepository($client);
-$genres = $repository->loadCollection();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new GenreRepository($client);
+$genres = $repository->loadCollection();
foreach ($genres as $genre) {
var_dump($genre);
diff --git a/examples/genres/model/allmovies.php b/examples/genres/model/allmovies.php
index b38ecfb4..f0cb8738 100644
--- a/examples/genres/model/allmovies.php
+++ b/examples/genres/model/allmovies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\GenreRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\GenreRepository($client);
-$genres = $repository->loadMovieCollection();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new GenreRepository($client);
+$genres = $repository->loadMovieCollection();
foreach ($genres as $genre) {
var_dump($genre);
diff --git a/examples/genres/model/alltv.php b/examples/genres/model/alltv.php
index 6c4f6273..c99ec9df 100644
--- a/examples/genres/model/alltv.php
+++ b/examples/genres/model/alltv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\GenreRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\GenreRepository($client);
-$genres = $repository->loadTvCollection();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new GenreRepository($client);
+$genres = $repository->loadTvCollection();
foreach ($genres as $genre) {
var_dump($genre);
diff --git a/examples/genres/model/get.php b/examples/genres/model/get.php
index 212f7471..c6467724 100644
--- a/examples/genres/model/get.php
+++ b/examples/genres/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\GenreRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\GenreRepository($client);
-$genre = $repository->load(28);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new GenreRepository($client);
+$genre = $repository->load(28);
var_dump($genre);
diff --git a/examples/genres/model/movies.php b/examples/genres/model/movies.php
index 03eb1915..61c6c221 100644
--- a/examples/genres/model/movies.php
+++ b/examples/genres/model/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\GenreRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\GenreRepository($client);
-$genre = $repository->getMovies(18);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new GenreRepository($client);
+$genre = $repository->getMovies(18);
var_dump($genre);
diff --git a/examples/global_adult_filter.php b/examples/global_adult_filter.php
index 5f06c34b..f9c3c3a0 100644
--- a/examples/global_adult_filter.php
+++ b/examples/global_adult_filter.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\AdultFilterRequestListener;
+use Tmdb\Repository\MovieRepository;
+
require_once '../vendor/autoload.php';
-require_once '../apikey.php';
+require_once 'apikey.php';
+
+/** @var Tmdb\Client $client * */
+$client = require_once('setup-client.php');
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+/** @var Symfony\Component\EventDispatcher\EventDispatcher $ed */
+$ed = $client->getEventDispatcher();
+$ed->addListener(
+ BeforeRequestEvent::class,
+ new AdultFilterRequestListener(true)
+);
-$plugin = new \Tmdb\HttpClient\Plugin\AdultFilterPlugin(); // explicitly set this to true to show adult results
-$client->getHttpClient()->addSubscriber($plugin);
+$repository = new MovieRepository($client);
+$movie = $repository->load(19995);
diff --git a/examples/global_language_filter.php b/examples/global_language_filter.php
index 38faa704..39153a1d 100644
--- a/examples/global_language_filter.php
+++ b/examples/global_language_filter.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\LanguageFilterRequestListener;
+use Tmdb\Repository\MovieRepository;
+
require_once '../vendor/autoload.php';
-require_once '../apikey.php';
+require_once 'apikey.php';
+
+/** @var Tmdb\Client $client * */
+$client = require_once('setup-client.php');
+
+/** @var Symfony\Component\EventDispatcher\EventDispatcher $ed */
+$ed = $client->getEventDispatcher();
+$ed->addListener(
+ BeforeRequestEvent::class,
+ new LanguageFilterRequestListener('nl-NL')
+);
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-$plugin = new \Tmdb\HttpClient\Plugin\LanguageFilterPlugin('nl');
-$client->getHttpClient()->addSubscriber($plugin);
+$repository = new MovieRepository($client);
+$movie = $repository->load(19995);
diff --git a/examples/global_region_filter.php b/examples/global_region_filter.php
new file mode 100644
index 00000000..85658c86
--- /dev/null
+++ b/examples/global_region_filter.php
@@ -0,0 +1,33 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\Listener\Request\RegionFilterRequestListener;
+use Tmdb\Repository\MovieRepository;
+
+require_once '../vendor/autoload.php';
+require_once 'apikey.php';
+
+/** @var Tmdb\Client $client * */
+$client = require_once('setup-client.php');
+
+/** @var Symfony\Component\EventDispatcher\EventDispatcher $ed */
+$ed = $client->getEventDispatcher();
+$ed->addListener(
+ BeforeRequestEvent::class,
+ new RegionFilterRequestListener('nl')
+);
+
+$repository = new MovieRepository($client);
+$movie = $repository->load(19995);
diff --git a/examples/guest_session/api/rated_movies.php b/examples/guest_session/api/rated_movies.php
index 5dee4add..9174b153 100644
--- a/examples/guest_session/api/rated_movies.php
+++ b/examples/guest_session/api/rated_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\GuestSessionToken;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client-guest-session.php');
$rated_movies = $client->getGuestSessionApi()->getRatedMovies();
diff --git a/examples/guest_session/model/rated_movies.php b/examples/guest_session/model/rated_movies.php
index 0b5d33ad..e289bec1 100644
--- a/examples/guest_session/model/rated_movies.php
+++ b/examples/guest_session/model/rated_movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\SessionToken(TMDB_SESSION_TOKEN)]);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client-guest-session.php');
/**
* @var \Tmdb\Repository\GuestSessionRepository $guestSessionRepository
diff --git a/examples/jobs/api/all.php b/examples/jobs/api/all.php
index d8762864..780132fb 100644
--- a/examples/jobs/api/all.php
+++ b/examples/jobs/api/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
$jobs = $client->getJobsApi()->getJobs();
var_dump($jobs);
diff --git a/examples/jobs/model/all.php b/examples/jobs/model/all.php
index a4fa258f..44f03b6f 100644
--- a/examples/jobs/model/all.php
+++ b/examples/jobs/model/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\JobsRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\JobsRepository($client);
-$jobs = $repository->loadCollection();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$repository = new JobsRepository($client);
+$jobs = $repository->loadCollection();
foreach ($jobs as $job) {
var_dump($job);
diff --git a/examples/keywords/api/get.php b/examples/keywords/api/get.php
index 686b3658..857dbd51 100644
--- a/examples/keywords/api/get.php
+++ b/examples/keywords/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$keyword = $client->getKeywordsApi()->getKeyword(1721);
var_dump($keyword);
diff --git a/examples/keywords/api/movies.php b/examples/keywords/api/movies.php
index 8cdc6972..954737be 100644
--- a/examples/keywords/api/movies.php
+++ b/examples/keywords/api/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$movies = $client->getKeywordsApi()->getMovies(1721);
var_dump($movies);
diff --git a/examples/keywords/model/get.php b/examples/keywords/model/get.php
index 8babf524..14baefa9 100644
--- a/examples/keywords/model/get.php
+++ b/examples/keywords/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\KeywordRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\KeywordRepository($client);
-$keyword = $repository->load(1721);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new KeywordRepository($client);
+$keyword = $repository->load(1721);
var_dump($keyword);
diff --git a/examples/keywords/model/movies.php b/examples/keywords/model/movies.php
index 556c6c23..5d291d5c 100644
--- a/examples/keywords/model/movies.php
+++ b/examples/keywords/model/movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\KeywordRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\KeywordRepository($client);
-$movies = $repository->getMovies(1721);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new KeywordRepository($client);
+$movies = $repository->getMovies(1721);
var_dump($movies);
diff --git a/examples/lists/api/add.php b/examples/lists/api/add.php
index a65935e6..b8bd2079 100644
--- a/examples/lists/api/add.php
+++ b/examples/lists/api/add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\SessionToken;
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$add = $client->getListsApi()->addMediaToList(TMDB_LIST_ID, 49047);
var_dump($add);
diff --git a/examples/lists/api/get.php b/examples/lists/api/get.php
index 45763d3c..8822b086 100644
--- a/examples/lists/api/get.php
+++ b/examples/lists/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$list = $client->getListsApi()->getList('509ec17b19c2950a0600050d');
+$list = $client->getListsApi()->getList(TMDB_LIST_ID);
var_dump($list);
diff --git a/examples/lists/api/item_status.php b/examples/lists/api/item_status.php
index 691fb44f..e2d384ea 100644
--- a/examples/lists/api/item_status.php
+++ b/examples/lists/api/item_status.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$remove = $client->getListsApi()->getItemStatus(TMDB_LIST_ID, 49047);
diff --git a/examples/lists/api/list_clear.php b/examples/lists/api/list_clear.php
index f95ecbf9..87de0871 100644
--- a/examples/lists/api/list_clear.php
+++ b/examples/lists/api/list_clear.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$clear = $client->getListsApi()->clearList(TMDB_LIST_ID, true);
var_dump($clear);
diff --git a/examples/lists/api/list_create.php b/examples/lists/api/list_create.php
index 5c2f1cee..2c4dd79e 100644
--- a/examples/lists/api/list_create.php
+++ b/examples/lists/api/list_create.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$create = $client->getListsApi()->createList('test', 'test description');
diff --git a/examples/lists/api/list_delete.php b/examples/lists/api/list_delete.php
index 1671caf8..92208ef7 100644
--- a/examples/lists/api/list_delete.php
+++ b/examples/lists/api/list_delete.php
@@ -1,4 +1,7 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client-session.php');
$create = $client->getListsApi()->deleteList(TMDB_LIST_ID);
diff --git a/examples/lists/api/remove.php b/examples/lists/api/remove.php
index 789f521d..ab745920 100644
--- a/examples/lists/api/remove.php
+++ b/examples/lists/api/remove.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$remove = $client->getListsApi()->removeMediaFromList(TMDB_LIST_ID, 49047);
diff --git a/examples/lists/model/add.php b/examples/lists/model/add.php
index 55abd05b..13769dfa 100644
--- a/examples/lists/model/add.php
+++ b/examples/lists/model/add.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ListRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\ListRepository($client);
-$result = $repository->add(TMDB_LIST_ID, 150);
+$repository = new ListRepository($client);
+$result = $repository->add(TMDB_LIST_ID, 150);
var_dump($result);
diff --git a/examples/lists/model/get.php b/examples/lists/model/get.php
index 4cea0f20..5ced48a9 100644
--- a/examples/lists/model/get.php
+++ b/examples/lists/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ListRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\ListRepository($client);
-$list = $repository->load('509ec17b19c2950a0600050d');
+$repository = new ListRepository($client);
+$list = $repository->load('509ec17b19c2950a0600050d');
var_dump($list);
diff --git a/examples/lists/model/item_status.php b/examples/lists/model/item_status.php
index b3f7d7bc..72683a9c 100644
--- a/examples/lists/model/item_status.php
+++ b/examples/lists/model/item_status.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ListRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\ListRepository($client);
-$list = $repository->getItemStatus('509ec17b19c2950a0600050d', 150);
+$repository = new ListRepository($client);
+$list = $repository->getItemStatus('509ec17b19c2950a0600050d', 150);
var_dump($list);
diff --git a/examples/lists/model/list_create.php b/examples/lists/model/list_create.php
index 012c3999..d0bf0021 100644
--- a/examples/lists/model/list_create.php
+++ b/examples/lists/model/list_create.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ListRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\ListRepository($client);
-$result = $repository->createList('php-tmdb-api', 'just a test');
+$repository = new ListRepository($client);
+$result = $repository->createList('php-tmdb-api', 'just a test');
var_dump($result);
diff --git a/examples/lists/model/list_delete.php b/examples/lists/model/list_delete.php
index f2e7c34b..cd1531ea 100644
--- a/examples/lists/model/list_delete.php
+++ b/examples/lists/model/list_delete.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ListRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\ListRepository($client);
-$result = $repository->remove(TMDB_LIST_ID, 150);
+$repository = new ListRepository($client);
+$result = $repository->remove(TMDB_LIST_ID, 150);
var_dump($result);
diff --git a/examples/logging.php b/examples/logging.php
index 7917513b..28db202b 100644
--- a/examples/logging.php
+++ b/examples/logging.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Monolog\Handler\StreamHandler;
+use Monolog\Logger;
+use Psr\Log\LogLevel;
+use Tmdb\Event\BeforeHydrationEvent;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\HttpClientExceptionEvent;
+use Tmdb\Event\Listener\Logger\LogApiErrorListener;
+use Tmdb\Event\Listener\Logger\LogHttpMessageListener;
+use Tmdb\Event\Listener\Logger\LogHydrationListener;
+use Tmdb\Event\ResponseEvent;
+use Tmdb\Event\TmdbExceptionEvent;
+use Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter;
+use Tmdb\Formatter\Hydration\SimpleHydrationFormatter;
+use Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter;
+use Tmdb\Repository\MovieRepository;
+
require_once '../vendor/autoload.php';
-require_once '../apikey.php';
+require_once 'apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
+/** @var Tmdb\Client $client * */
+$client = require_once('setup-client.php');
+$ed = $client->getEventDispatcher();
-// A simple change the path of the log
-/*
-$client = new \Tmdb\Client($token, [
- 'log' => [
- 'enabled' => true,
- 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'application-api.log'
- ]
-]);
-*/
-
-// If you'd like to know what's going on during development, something like this could prove handy.
-$client = new \Tmdb\Client($token, [
- 'log' => [
- 'enabled' => true,
- 'handler' => new \Monolog\Handler\ChromePHPHandler() // chrome php extension
-// 'handler' => new \Monolog\Handler\FirePHPHandler() // firefox php extension
+$logger = new Logger(
+ 'php-tmdb',
+ [
+ new StreamHandler(__DIR__ . '/var/log/php-tmdb.log', LogLevel::DEBUG)
]
-]);
+);
+
+// Optional for logging, you can also omit events you do not wish to be logged.
+$requestLoggerListener = new LogHttpMessageListener(
+ $logger,
+ new SimpleHttpMessageFormatter()
+);
+$hydrationLoggerListener = new LogHydrationListener(
+ $logger,
+ new SimpleHydrationFormatter(),
+ true // set to true if you wish to add the json data passed for each hydration, do not use this on production
+);
+$apiErrorListener = new LogApiErrorListener(
+ $logger,
+ new SimpleTmdbApiExceptionFormatter()
+);
+
+$ed->addListener(BeforeRequestEvent::class, $requestLoggerListener);
+$ed->addListener(ResponseEvent::class, $requestLoggerListener);
+$ed->addListener(HttpClientExceptionEvent::class, $requestLoggerListener);
+
+$ed->addListener(TmdbExceptionEvent::class, $apiErrorListener);
+$ed->addListener(BeforeHydrationEvent::class, $hydrationLoggerListener);
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(19995);
+$repository = new MovieRepository($client);
+$movie = $repository->load(19995);
diff --git a/examples/movies/api/account_states.php b/examples/movies/api/account_states.php
index acd242c7..ce5a25f3 100644
--- a/examples/movies/api/account_states.php
+++ b/examples/movies/api/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$accountStates = $client->getMoviesApi()->getAccountStates(550, true);
diff --git a/examples/movies/api/all.php b/examples/movies/api/all.php
index 128a29c8..45b8bf82 100644
--- a/examples/movies/api/all.php
+++ b/examples/movies/api/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
header('Content-Type: text/html; charset=utf-8');
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$movie = $client->getMoviesApi()->getMovie(87421);
var_dump($movie);
diff --git a/examples/movies/api/alternative_titles.php b/examples/movies/api/alternative_titles.php
index c2c2eb33..e42f75c6 100644
--- a/examples/movies/api/alternative_titles.php
+++ b/examples/movies/api/alternative_titles.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$alternativeTitles = $client->getMoviesApi()->getAlternativeTitles(87421);
var_dump($alternativeTitles);
diff --git a/examples/movies/api/changes.php b/examples/movies/api/changes.php
index af2b81a5..d9258f46 100644
--- a/examples/movies/api/changes.php
+++ b/examples/movies/api/changes.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$changes = $client->getMoviesApi()->getChanges(87421);
var_dump($changes);
diff --git a/examples/movies/api/credits.php b/examples/movies/api/credits.php
index 43e6a140..6fb977b9 100644
--- a/examples/movies/api/credits.php
+++ b/examples/movies/api/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credits = $client->getMoviesApi()->getCredits(87421);
var_dump($credits);
diff --git a/examples/movies/api/get.php b/examples/movies/api/get.php
index b5f8fe57..1480eb66 100644
--- a/examples/movies/api/get.php
+++ b/examples/movies/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(87421);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
+$movie = $repository->load(87421);
var_dump($movie);
diff --git a/examples/movies/api/images.php b/examples/movies/api/images.php
index 1d701df4..52f0ccb1 100644
--- a/examples/movies/api/images.php
+++ b/examples/movies/api/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$images = $client->getMoviesApi()->getImages(550);
+
+var_dump($images);
diff --git a/examples/movies/api/keywords.php b/examples/movies/api/keywords.php
index 08b4a495..3f649cf0 100644
--- a/examples/movies/api/keywords.php
+++ b/examples/movies/api/keywords.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$keywords = $client->getMoviesApi()->getKeywords(87421);
var_dump($keywords);
diff --git a/examples/movies/api/lists.php b/examples/movies/api/lists.php
index 655687da..986b3df3 100644
--- a/examples/movies/api/lists.php
+++ b/examples/movies/api/lists.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$lists = $client->getMoviesApi()->getLists(87421);
var_dump($lists);
diff --git a/examples/movies/api/movie_rating.php b/examples/movies/api/movie_rating.php
index f026ee77..ceab4fdb 100644
--- a/examples/movies/api/movie_rating.php
+++ b/examples/movies/api/movie_rating.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$rating = $client->getMoviesApi()->rateMovie(550, 8.5);
diff --git a/examples/movies/api/recommendations.php b/examples/movies/api/recommendations.php
index 8275f626..25a62cb7 100644
--- a/examples/movies/api/recommendations.php
+++ b/examples/movies/api/recommendations.php
@@ -1,4 +1,5 @@
* @copyright (c) 2018, Eugenia Schneider
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$recommendedMovies = $client->getMoviesApi()->getRecommendations(87421);
var_dump($recommendedMovies);
diff --git a/examples/movies/api/releases.php b/examples/movies/api/releases.php
index 4f6bf4cd..365ea684 100644
--- a/examples/movies/api/releases.php
+++ b/examples/movies/api/releases.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$releases = $client->getMoviesApi()->getReleases(87421);
var_dump($releases);
diff --git a/examples/movies/api/reviews.php b/examples/movies/api/reviews.php
index e5f55810..005f9177 100644
--- a/examples/movies/api/reviews.php
+++ b/examples/movies/api/reviews.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$reviews = $client->getMoviesApi()->getReviews(87421);
var_dump($reviews);
diff --git a/examples/movies/api/similar.php b/examples/movies/api/similar.php
index a756e623..498a7ce3 100644
--- a/examples/movies/api/similar.php
+++ b/examples/movies/api/similar.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$similarMovies = $client->getMoviesApi()->getSimilar(87421);
var_dump($similarMovies);
diff --git a/examples/movies/api/trailers.php b/examples/movies/api/trailers.php
index 69280b4f..594b4013 100644
--- a/examples/movies/api/trailers.php
+++ b/examples/movies/api/trailers.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$trailers = $client->getMoviesApi()->getTrailers(87421);
var_dump($trailers);
diff --git a/examples/movies/api/videos.php b/examples/movies/api/videos.php
index 0d8b0ac1..9399568e 100644
--- a/examples/movies/api/videos.php
+++ b/examples/movies/api/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$videos = $client->getMoviesApi()->getVideos(87421);
var_dump($videos);
diff --git a/examples/movies/model/account_states.php b/examples/movies/model/account_states.php
index 83e30e57..08d847d8 100644
--- a/examples/movies/model/account_states.php
+++ b/examples/movies/model/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\MovieRepository($client);
+$repository = new MovieRepository($client);
$accountStates = $repository->getAccountStates(97020);
var_dump($accountStates);
diff --git a/examples/movies/model/all.php b/examples/movies/model/all.php
index 2b379e56..a6dd61eb 100644
--- a/examples/movies/model/all.php
+++ b/examples/movies/model/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Helper\ImageHelper;
+use Tmdb\Model\Image\PosterImage;
+use Tmdb\Model\Movie;
+use Tmdb\Repository\ConfigurationRepository;
+use Tmdb\Repository\MovieRepository;
+
header('Content-Type: text/html; charset=utf-8');
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../apikey.php';
-$configRepository = new \Tmdb\Repository\ConfigurationRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$configRepository = new ConfigurationRepository($client);
$config = $configRepository->load();
-$imageHelper = new \Tmdb\Helper\ImageHelper($config);
-$repository = new \Tmdb\Repository\MovieRepository($client);
+$imageHelper = new ImageHelper($config);
+$repository = new MovieRepository($client);
/**
- * @var \Tmdb\Model\Movie $movie
+ * @var Movie $movie
*/
$movie = $repository->load(87421);
-var_dump($movie);exit;
+var_dump($movie);
+exit;
echo $movie->getTitle() . "
";
echo "Alternative Titles
";
@@ -54,11 +62,15 @@
echo "Images
";
// All collection classes support filtering by closure functions, provided by the generic collection implementation.
-foreach($movie->getImages()->filter(
+foreach (
+ $movie->getImages()->filter(
function ($key, $value) {
- if ($value->getIso6391() == 'en' && $value instanceof \Tmdb\Model\Image\PosterImage) { return true; }
+ if ($value->getIso6391() == 'en' && $value instanceof PosterImage) {
+ return true;
+ }
}
- ) as $image) {
+ ) as $image
+) {
echo $imageHelper->getHtml($image, 'w154', 150);
printf(" - %s
", $imageHelper->getUrl($image));
@@ -68,8 +80,7 @@ function ($key, $value) {
$backdrop = $movie
->getImages()
->filterBackdrops()
- ->filterBestVotedImage()
-;
+ ->filterBestVotedImage();
echo $imageHelper->getHtml($backdrop, 'original', '1024');
diff --git a/examples/movies/model/alternative_titles.php b/examples/movies/model/alternative_titles.php
index cf130c04..487e3a6d 100644
--- a/examples/movies/model/alternative_titles.php
+++ b/examples/movies/model/alternative_titles.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getAlternativeTitles(87421);
var_dump($collection);
diff --git a/examples/movies/model/cache/basic_doctrine_cache.php b/examples/movies/model/cache/basic_doctrine_cache.php
deleted file mode 100644
index 3d6d3eba..00000000
--- a/examples/movies/model/cache/basic_doctrine_cache.php
+++ /dev/null
@@ -1,24 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-
-$client->setCaching(true);
-
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(87421);
-
-var_dump($movie);
diff --git a/examples/movies/model/cache/built-in.php b/examples/movies/model/cache/built-in.php
deleted file mode 100644
index 50fea79c..00000000
--- a/examples/movies/model/cache/built-in.php
+++ /dev/null
@@ -1,24 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-
-$client->setCaching(true, '/tmp/php-tmdb-api');
-
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(87421);
-
-echo $movie->getTitle();
diff --git a/examples/movies/model/changes.php b/examples/movies/model/changes.php
index 21ca4e71..0e32b7ce 100644
--- a/examples/movies/model/changes.php
+++ b/examples/movies/model/changes.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getChanges(87421);
var_dump($collection);
diff --git a/examples/movies/model/credits.php b/examples/movies/model/credits.php
index 835e3cd6..7c4f3e31 100644
--- a/examples/movies/model/credits.php
+++ b/examples/movies/model/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getCredits(87421);
var_dump($collection);
diff --git a/examples/movies/model/get.php b/examples/movies/model/get.php
index b5f8fe57..1480eb66 100644
--- a/examples/movies/model/get.php
+++ b/examples/movies/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$movie = $repository->load(87421);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
+$movie = $repository->load(87421);
var_dump($movie);
diff --git a/examples/movies/model/images.php b/examples/movies/model/images.php
index ce9fdcc0..e449cef8 100644
--- a/examples/movies/model/images.php
+++ b/examples/movies/model/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getImages(87421);
var_dump($collection);
diff --git a/examples/movies/model/keywords.php b/examples/movies/model/keywords.php
index d8ae94b3..4565a83c 100644
--- a/examples/movies/model/keywords.php
+++ b/examples/movies/model/keywords.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getKeywords(87421);
var_dump($collection);
diff --git a/examples/movies/model/lists.php b/examples/movies/model/lists.php
index a53feb58..14f9227d 100644
--- a/examples/movies/model/lists.php
+++ b/examples/movies/model/lists.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getLists(87421);
var_dump($collection);
diff --git a/examples/movies/model/popular.php b/examples/movies/model/popular.php
index 8f223f11..154831e7 100644
--- a/examples/movies/model/popular.php
+++ b/examples/movies/model/popular.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getPopular();
var_dump($collection);
diff --git a/examples/movies/model/rate.php b/examples/movies/model/rate.php
index c64690ce..6d455468 100644
--- a/examples/movies/model/rate.php
+++ b/examples/movies/model/rate.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token, ['session_token' => new \Tmdb\GuestSessionToken(TMDB_GUEST_SESSION_TOKEN), 'log' => ['enabled' => true, 'handler' => new \Monolog\Handler\ChromePHPHandler()]]);
+use Tmdb\Repository\MovieRepository;
-/**
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
-*/
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$guestSessionToken = new \Tmdb\GuestSessionToken(TMDB_GUEST_SESSION_TOKEN);
-$client->setSessionToken($guestSessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ \Tmdb\Event\BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new \Tmdb\Token\Session\SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\MovieRepository($client);
+$repository = new MovieRepository($client);
$rate = $repository->rate(49047, 6.5);
var_dump($rate);
diff --git a/examples/movies/model/recommendations.php b/examples/movies/model/recommendations.php
index 3c626439..ea05bdb0 100644
--- a/examples/movies/model/recommendations.php
+++ b/examples/movies/model/recommendations.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getRecommendations(87421);
var_dump($collection);
diff --git a/examples/movies/model/releases.php b/examples/movies/model/releases.php
index 4b5f6c33..a0b74e24 100644
--- a/examples/movies/model/releases.php
+++ b/examples/movies/model/releases.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getReleases(87421);
var_dump($collection);
diff --git a/examples/movies/model/reviews.php b/examples/movies/model/reviews.php
index 0331307e..1390d947 100644
--- a/examples/movies/model/reviews.php
+++ b/examples/movies/model/reviews.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getReviews(87421);
var_dump($collection);
diff --git a/examples/movies/model/similar.php b/examples/movies/model/similar.php
index 30e38f21..a933c668 100644
--- a/examples/movies/model/similar.php
+++ b/examples/movies/model/similar.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getSimilar(87421);
var_dump($collection);
diff --git a/examples/movies/model/videos.php b/examples/movies/model/videos.php
index 0efc1532..4216e971 100644
--- a/examples/movies/model/videos.php
+++ b/examples/movies/model/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\MovieRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\MovieRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new MovieRepository($client);
$collection = $repository->getVideos(87421);
var_dump($collection);
diff --git a/examples/networks/api/get.php b/examples/networks/api/get.php
index 9574eaa7..29340343 100644
--- a/examples/networks/api/get.php
+++ b/examples/networks/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$network = $client->getNetworksApi()->getNetwork(49);
var_dump($network);
diff --git a/examples/networks/model/get.php b/examples/networks/model/get.php
index bd8a8466..7dcc7e3e 100644
--- a/examples/networks/model/get.php
+++ b/examples/networks/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\NetworkRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\NetworkRepository($client);
-$network = $repository->load(49);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new NetworkRepository($client);
+$network = $repository->load(49);
var_dump($network);
diff --git a/examples/people/api/all.php b/examples/people/api/all.php
index 8c5e413c..2153425b 100644
--- a/examples/people/api/all.php
+++ b/examples/people/api/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$person = $client->getPeopleApi()->getPerson(33);
var_dump($person);
diff --git a/examples/people/api/combined_credits.php b/examples/people/api/combined_credits.php
index 23e12730..e56b46df 100644
--- a/examples/people/api/combined_credits.php
+++ b/examples/people/api/combined_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credits = $client->getPeopleApi()->getCombinedCredits(33);
var_dump($credits);
diff --git a/examples/people/api/external_ids.php b/examples/people/api/external_ids.php
index 4fce1a7d..10ef1e3c 100644
--- a/examples/people/api/external_ids.php
+++ b/examples/people/api/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$externalIds = $client->getPeopleApi()->getExternalIds(33);
var_dump($externalIds);
diff --git a/examples/people/api/latest.php b/examples/people/api/latest.php
index 4d67e2c7..4119bb0f 100644
--- a/examples/people/api/latest.php
+++ b/examples/people/api/latest.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$latestMovies = $client->getPeopleApi()->getLatest();
var_dump($latestMovies);
diff --git a/examples/people/api/movie_credits.php b/examples/people/api/movie_credits.php
index f3d66450..6992ee7f 100644
--- a/examples/people/api/movie_credits.php
+++ b/examples/people/api/movie_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$credits = $client->getPeopleApi()->getMovieCredits(33);
var_dump($credits);
diff --git a/examples/people/api/popular.php b/examples/people/api/popular.php
index e79ec695..a34d81f3 100644
--- a/examples/people/api/popular.php
+++ b/examples/people/api/popular.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$popularMovies = $client->getPeopleApi()->getPopular();
var_dump($popularMovies);
diff --git a/examples/people/api/tagged_images.php b/examples/people/api/tagged_images.php
index 2f118ca7..5064ac05 100644
--- a/examples/people/api/tagged_images.php
+++ b/examples/people/api/tagged_images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$taggedImages = $client->getPeopleApi()->getTaggedImages(287);
var_dump($taggedImages);
diff --git a/examples/people/api/tv_credits.php b/examples/people/api/tv_credits.php
index 6b1f964b..5a36167c 100644
--- a/examples/people/api/tv_credits.php
+++ b/examples/people/api/tv_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$person = $client->getPeopleApi()->getTvCredits(33);
var_dump($person);
diff --git a/examples/people/model/all.php b/examples/people/model/all.php
index 5d54e105..225040f1 100644
--- a/examples/people/model/all.php
+++ b/examples/people/model/all.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$person = $repository->load(33);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$person = $repository->load(33);
var_dump($person);
diff --git a/examples/people/model/combined_credits.php b/examples/people/model/combined_credits.php
index 4c2acb08..bd3cbbf7 100644
--- a/examples/people/model/combined_credits.php
+++ b/examples/people/model/combined_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$person = $repository->getCombinedCredits(33);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$person = $repository->getCombinedCredits(33);
var_dump($person);
diff --git a/examples/people/model/external_ids.php b/examples/people/model/external_ids.php
index c182f7cb..1a2ff6f7 100644
--- a/examples/people/model/external_ids.php
+++ b/examples/people/model/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
$externalIds = $repository->getExternalIds(287);
var_dump($externalIds);
diff --git a/examples/people/model/latest.php b/examples/people/model/latest.php
index 4f0474db..abf31b94 100644
--- a/examples/people/model/latest.php
+++ b/examples/people/model/latest.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$latest = $repository->getLatest();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$latest = $repository->getLatest();
var_dump($latest);
diff --git a/examples/people/model/movie_credits.php b/examples/people/model/movie_credits.php
index cf0e4581..700a0e80 100644
--- a/examples/people/model/movie_credits.php
+++ b/examples/people/model/movie_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$person = $repository->getMovieCredits(33);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$person = $repository->getMovieCredits(33);
var_dump($person);
diff --git a/examples/people/model/popular.php b/examples/people/model/popular.php
index bc84b48c..6fe84dff 100644
--- a/examples/people/model/popular.php
+++ b/examples/people/model/popular.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$popular = $repository->getPopular();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$popular = $repository->getPopular();
var_dump($popular);
diff --git a/examples/people/model/tagged_images.php b/examples/people/model/tagged_images.php
index fda56bc4..0c7b0854 100644
--- a/examples/people/model/tagged_images.php
+++ b/examples/people/model/tagged_images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Repository\PeopleRepository;
+
ini_set('display_errors', 'On');
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$person = $repository->getTaggedImages(287);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$person = $repository->getTaggedImages(287);
var_dump($person);
diff --git a/examples/people/model/tv_credits.php b/examples/people/model/tv_credits.php
index d526dec3..093c93c0 100644
--- a/examples/people/model/tv_credits.php
+++ b/examples/people/model/tv_credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\PeopleRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\PeopleRepository($client);
-$person = $repository->getTvCredits(33);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new PeopleRepository($client);
+$person = $repository->getTvCredits(33);
var_dump($person);
diff --git a/examples/phpunit b/examples/phpunit
deleted file mode 120000
index 86839e26..00000000
--- a/examples/phpunit
+++ /dev/null
@@ -1 +0,0 @@
-../build/coverage/
\ No newline at end of file
diff --git a/examples/reviews/api/get.php b/examples/reviews/api/get.php
index 8db5e138..d066e5db 100644
--- a/examples/reviews/api/get.php
+++ b/examples/reviews/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$review = $client->getReviewsApi()->getReview('5013bc76760ee372cb00253e');
var_dump($review);
diff --git a/examples/reviews/model/get.php b/examples/reviews/model/get.php
index d2ecc925..6fac83b4 100644
--- a/examples/reviews/model/get.php
+++ b/examples/reviews/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\ReviewRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\ReviewRepository($client);
-$review = $repository->load('5013bc76760ee372cb00253e');
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$repository = new ReviewRepository($client);
+$review = $repository->load('5013bc76760ee372cb00253e');
var_dump($review);
diff --git a/examples/search/api/collection.php b/examples/search/api/collection.php
index 4d493873..4aee4396 100644
--- a/examples/search/api/collection.php
+++ b/examples/search/api/collection.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchCollection('star wars');
var_dump($result);
diff --git a/examples/search/api/company.php b/examples/search/api/company.php
index d29339b4..9033db34 100644
--- a/examples/search/api/company.php
+++ b/examples/search/api/company.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchCompany('warner bros');
var_dump($result);
diff --git a/examples/search/api/keyword.php b/examples/search/api/keyword.php
index b81a22e1..ce9ccdd0 100644
--- a/examples/search/api/keyword.php
+++ b/examples/search/api/keyword.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchKeyword('scary');
var_dump($result);
diff --git a/examples/search/api/movie.php b/examples/search/api/movie.php
index 0b788af0..5399c714 100644
--- a/examples/search/api/movie.php
+++ b/examples/search/api/movie.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchMovies('batman');
var_dump($result);
diff --git a/examples/search/api/multi.php b/examples/search/api/multi.php
index 60b0b40c..de395fc5 100644
--- a/examples/search/api/multi.php
+++ b/examples/search/api/multi.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchMulti('jack');
var_dump($result);
diff --git a/examples/search/api/person.php b/examples/search/api/person.php
index 0a737a43..3b294212 100644
--- a/examples/search/api/person.php
+++ b/examples/search/api/person.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchPersons('bruce lee');
var_dump($result);
diff --git a/examples/search/api/tv.php b/examples/search/api/tv.php
index cae9e169..5f9291e5 100644
--- a/examples/search/api/tv.php
+++ b/examples/search/api/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$result = $client->getSearchApi()->searchTv('breaking bad');
var_dump($result);
diff --git a/examples/search/model/collection.php b/examples/search/model/collection.php
index 68739cbd..c55ce519 100644
--- a/examples/search/model/collection.php
+++ b/examples/search/model/collection.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\CollectionSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\CollectionSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new CollectionSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchCollection('star wars', $query);
diff --git a/examples/search/model/company.php b/examples/search/model/company.php
index ed83814f..23bbab20 100644
--- a/examples/search/model/company.php
+++ b/examples/search/model/company.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\CompanySearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\CompanySearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new CompanySearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchCompany('warner bros', $query);
diff --git a/examples/search/model/keyword.php b/examples/search/model/keyword.php
index f1020e33..b852298a 100644
--- a/examples/search/model/keyword.php
+++ b/examples/search/model/keyword.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\KeywordSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\KeywordSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new KeywordSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchKeyword('scary', $query);
diff --git a/examples/search/model/list.php b/examples/search/model/list.php
deleted file mode 100644
index e2d8c621..00000000
--- a/examples/search/model/list.php
+++ /dev/null
@@ -1,26 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
-
-$query = new \Tmdb\Model\Search\SearchQuery\ListSearchQuery();
-$query->page(1);
-
-$repository = new \Tmdb\Repository\SearchRepository($client);
-
-$find = $repository->searchList('award', $query);
-
-var_dump($find);
diff --git a/examples/search/model/movie.php b/examples/search/model/movie.php
index bee0b527..0d26b94f 100644
--- a/examples/search/model/movie.php
+++ b/examples/search/model/movie.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\MovieSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\MovieSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new MovieSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchMovie('batman', $query);
diff --git a/examples/search/model/multi.php b/examples/search/model/multi.php
index 9d7e7099..6036c185 100644
--- a/examples/search/model/multi.php
+++ b/examples/search/model/multi.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\KeywordSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\KeywordSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new KeywordSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchMulti('jack', $query);
diff --git a/examples/search/model/person.php b/examples/search/model/person.php
index 2407a083..a2a4043d 100644
--- a/examples/search/model/person.php
+++ b/examples/search/model/person.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\PersonSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\PersonSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new PersonSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchPerson('bruce lee', $query);
diff --git a/examples/search/model/tv.php b/examples/search/model/tv.php
index a3fc32d9..27ee6477 100644
--- a/examples/search/model/tv.php
+++ b/examples/search/model/tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Model\Search\SearchQuery\TvSearchQuery;
+use Tmdb\Repository\SearchRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$query = new \Tmdb\Model\Search\SearchQuery\TvSearchQuery();
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
+$query = new TvSearchQuery();
$query->page(1);
-$repository = new \Tmdb\Repository\SearchRepository($client);
+$repository = new SearchRepository($client);
$find = $repository->searchTv('breaking bad', $query);
diff --git a/examples/setup-client-full.php b/examples/setup-client-full.php
new file mode 100644
index 00000000..fb8657fa
--- /dev/null
+++ b/examples/setup-client-full.php
@@ -0,0 +1,136 @@
+ $token,
+ 'secure' => true,
+ 'base_uri' => Client::TMDB_URI,
+ 'session_token' => null,
+ 'event_dispatcher' => [
+ 'adapter' => $ed
+ ],
+ // We make use of PSR-17 and PSR-18 auto discovery to automatically guess these, but preferably set these explicitly.
+ 'http' => [
+ 'client' => null,
+ 'request_factory' => null,
+ 'response_factory' => null,
+ 'stream_factory' => null,
+ 'uri_factory' => null,
+ ],
+ 'hydration' => [
+ 'event_listener_handles_hydration' => false,
+ 'only_for_specified_models' => []
+ ]
+ ]
+);
+
+/**
+ * Instantiate the PSR-6 cache
+ */
+$cache = new FilesystemAdapter('php-tmdb', 86400, __DIR__ . '/var/cache');
+
+/**
+ * The full setup makes use of the Psr6CachedRequestListener.
+ *
+ * Required event listeners and events to be registered with the PSR-14 Event Dispatcher.
+ */
+$requestListener = new Psr6CachedRequestListener(
+ $client->getHttpClient(),
+ $ed,
+ $cache,
+ $client->getHttpClient()->getPsr17StreamFactory(),
+ []
+);
+
+$ed->addListener(RequestEvent::class, $requestListener);
+
+$apiTokenListener = new ApiTokenRequestListener($client->getToken());
+$ed->addListener(BeforeRequestEvent::class, $apiTokenListener);
+
+$acceptJsonListener = new AcceptJsonRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $acceptJsonListener);
+
+$jsonContentTypeListener = new ContentTypeJsonRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $jsonContentTypeListener);
+
+/**
+ * Optional for logging, you can also omit events you do not wish to be logged.
+ */
+$requestLoggerListener = new LogHttpMessageListener(
+ $logger,
+ new \Tmdb\Formatter\HttpMessage\FullHttpMessageFormatter()
+);
+$ed->addListener(BeforeRequestEvent::class, $requestLoggerListener);
+$ed->addListener(ResponseEvent::class, $requestLoggerListener);
+$ed->addListener(HttpClientExceptionEvent::class, $requestLoggerListener);
+
+$hydrationLoggerListener = new LogHydrationListener(
+ $logger,
+ new SimpleHydrationFormatter(),
+ false // set to true if you wish to add the json data passed for each hydration, do not use this on production
+);
+$ed->addListener(BeforeHydrationEvent::class, $hydrationLoggerListener);
+
+$apiErrorListener = new LogApiErrorListener(
+ $logger,
+ new SimpleTmdbApiExceptionFormatter()
+);
+$ed->addListener(TmdbExceptionEvent::class, $apiErrorListener);
+
+/**
+ * Optional plugins.
+ */
+$adultFilterListener = new AdultFilterRequestListener(false);
+$ed->addListener(BeforeRequestEvent::class, $adultFilterListener);
+
+$languageFilterListener = new LanguageFilterRequestListener(TMDB_LANGUAGE);
+$ed->addListener(BeforeRequestEvent::class, $languageFilterListener);
+
+$regionFilterListener = new RegionFilterRequestListener(TMDB_REGION);
+$ed->addListener(BeforeRequestEvent::class, $regionFilterListener);
+
+$userAgentListener = new UserAgentRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $userAgentListener);
+
+return $client;
diff --git a/examples/setup-client.php b/examples/setup-client.php
new file mode 100644
index 00000000..458b3c5e
--- /dev/null
+++ b/examples/setup-client.php
@@ -0,0 +1,56 @@
+ $token,
+ 'event_dispatcher' => [
+ 'adapter' => $ed
+ ],
+ // We make use of PSR-17 and PSR-18 auto discovery to automatically guess these, but preferably set these explicitly.
+ 'http' => [
+ 'client' => null,
+ 'request_factory' => null,
+ 'response_factory' => null,
+ 'stream_factory' => null,
+ 'uri_factory' => null,
+ ]
+ ]
+);
+
+/**
+ * Required event listeners and events to be registered with the PSR-14 Event Dispatcher.
+ */
+$requestListener = new RequestListener($client->getHttpClient(), $ed);
+$ed->addListener(RequestEvent::class, $requestListener);
+
+$apiTokenListener = new ApiTokenRequestListener($client->getToken());
+$ed->addListener(BeforeRequestEvent::class, $apiTokenListener);
+
+$acceptJsonListener = new AcceptJsonRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $acceptJsonListener);
+
+$jsonContentTypeListener = new ContentTypeJsonRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $jsonContentTypeListener);
+
+$userAgentListener = new UserAgentRequestListener();
+$ed->addListener(BeforeRequestEvent::class, $userAgentListener);
+
+return $client;
diff --git a/examples/timezones/api/get.php b/examples/timezones/api/get.php
index 214684ac..3ec4e576 100644
--- a/examples/timezones/api/get.php
+++ b/examples/timezones/api/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
$timezones = $client->getTimezonesApi()->getTimezones();
var_dump($timezones);
diff --git a/examples/timezones/model/get.php b/examples/timezones/model/get.php
index d4647ac0..5f2cf719 100644
--- a/examples/timezones/model/get.php
+++ b/examples/timezones/model/get.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Repository\TimezoneRepository;
+
require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
+require_once '../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+/** @var Tmdb\Client $client **/
+$client = require_once('../../setup-client.php');
-$repository = new \Tmdb\Repository\TimezoneRepository($client);
-$timezones = $repository->getTimezones();
+$repository = new TimezoneRepository($client);
+$timezones = $repository->getTimezones();
var_dump($timezones->getCountry('NL')->supports('Europe/Amsterdam'));
diff --git a/examples/tv/api/episode.php b/examples/tv/api/episode.php
index d594d572..3cbe33aa 100644
--- a/examples/tv/api/episode.php
+++ b/examples/tv/api/episode.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
$episode = $client->getTvEpisodeApi()->getEpisode(1396, 2, 1);
var_dump($episode);
diff --git a/examples/tv/api/episode/account_states.php b/examples/tv/api/episode/account_states.php
index 3fac86b5..b5b2e3bd 100644
--- a/examples/tv/api/episode/account_states.php
+++ b/examples/tv/api/episode/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$result = $client->getTvEpisodeApi()->getAccountStates(1396, 1, 1);
diff --git a/examples/tv/api/episode/credits.php b/examples/tv/api/episode/credits.php
index a52e7de9..cb33fea9 100644
--- a/examples/tv/api/episode/credits.php
+++ b/examples/tv/api/episode/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvEpisodeApi()->getCredits(1396, 2, 1);
var_dump($result);
diff --git a/examples/tv/api/episode/external_ids.php b/examples/tv/api/episode/external_ids.php
index afae890e..7253d7b4 100644
--- a/examples/tv/api/episode/external_ids.php
+++ b/examples/tv/api/episode/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvEpisodeApi()->getExternalIds(1396, 2, 1);
var_dump($result);
diff --git a/examples/tv/api/episode/images.php b/examples/tv/api/episode/images.php
index c5760d6f..c4185fe2 100644
--- a/examples/tv/api/episode/images.php
+++ b/examples/tv/api/episode/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvEpisodeApi()->getImages(1396, 2, 1);
var_dump($result);
diff --git a/examples/tv/api/episode/rate.php b/examples/tv/api/episode/rate.php
index 6f4e40aa..8dda2840 100644
--- a/examples/tv/api/episode/rate.php
+++ b/examples/tv/api/episode/rate.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-ini_set('display_errors', 'On');
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$result = $client->getTvEpisodeApi()->rateTvEpisode(1396, 1, 1, 9.5);
diff --git a/examples/tv/api/episode/videos.php b/examples/tv/api/episode/videos.php
index 8350565a..6d76337d 100644
--- a/examples/tv/api/episode/videos.php
+++ b/examples/tv/api/episode/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvEpisodeApi()->getVideos(1396, 2, 1);
var_dump($result);
diff --git a/examples/tv/api/season.php b/examples/tv/api/season.php
index 01fc2102..24c5c09e 100644
--- a/examples/tv/api/season.php
+++ b/examples/tv/api/season.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
$season = $client->getTvSeasonApi()->getSeason(1396, 2);
var_dump($season);
diff --git a/examples/tv/api/season/credits.php b/examples/tv/api/season/credits.php
index 642093d7..2b57918b 100644
--- a/examples/tv/api/season/credits.php
+++ b/examples/tv/api/season/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvSeasonApi()->getCredits(1396, 2);
var_dump($result);
diff --git a/examples/tv/api/season/external_ids.php b/examples/tv/api/season/external_ids.php
index b5c0888b..d481e8e9 100644
--- a/examples/tv/api/season/external_ids.php
+++ b/examples/tv/api/season/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvSeasonApi()->getExternalIds(1396, 2);
var_dump($result);
diff --git a/examples/tv/api/season/images.php b/examples/tv/api/season/images.php
index 5731f273..d8d78095 100644
--- a/examples/tv/api/season/images.php
+++ b/examples/tv/api/season/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvSeasonApi()->getImages(1396, 2);
var_dump($result);
diff --git a/examples/tv/api/season/videos.php b/examples/tv/api/season/videos.php
index 7feaf722..d7a5433f 100644
--- a/examples/tv/api/season/videos.php
+++ b/examples/tv/api/season/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvSeasonApi()->getVideos(1396, 2);
var_dump($result);
diff --git a/examples/tv/api/show.php b/examples/tv/api/show.php
index e278971a..b9bd26ed 100644
--- a/examples/tv/api/show.php
+++ b/examples/tv/api/show.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
$tvShow = $client->getTvApi()->getTvshow(1396);
var_dump($tvShow);
diff --git a/examples/tv/api/tv/account_states.php b/examples/tv/api/tv/account_states.php
index 6f04d0c0..0e21716f 100644
--- a/examples/tv/api/tv/account_states.php
+++ b/examples/tv/api/tv/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$result = $client->getTvApi()->getAccountStates(1396);
diff --git a/examples/tv/api/tv/airing_today.php b/examples/tv/api/tv/airing_today.php
index 733dc666..19173cd9 100644
--- a/examples/tv/api/tv/airing_today.php
+++ b/examples/tv/api/tv/airing_today.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getAiringToday();
var_dump($result);
diff --git a/examples/tv/api/tv/alternative_titles.php b/examples/tv/api/tv/alternative_titles.php
index 35863369..5f12e475 100644
--- a/examples/tv/api/tv/alternative_titles.php
+++ b/examples/tv/api/tv/alternative_titles.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getAlternativeTitles(1396);
var_dump($result);
diff --git a/examples/tv/api/tv/content_ratings.php b/examples/tv/api/tv/content_ratings.php
index 98ef494f..b5745730 100644
--- a/examples/tv/api/tv/content_ratings.php
+++ b/examples/tv/api/tv/content_ratings.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$contentRatings = $client->getTvApi()->getcontentRatings(1396);
var_dump($contentRatings);
diff --git a/examples/tv/api/tv/credits.php b/examples/tv/api/tv/credits.php
index d75e44ac..d42b0a25 100644
--- a/examples/tv/api/tv/credits.php
+++ b/examples/tv/api/tv/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getCredits(1396);
var_dump($result);
diff --git a/examples/tv/api/tv/external_ids.php b/examples/tv/api/tv/external_ids.php
index f876e0d1..fcb3be85 100644
--- a/examples/tv/api/tv/external_ids.php
+++ b/examples/tv/api/tv/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getExternalIds(1396);
var_dump($result);
diff --git a/examples/tv/api/tv/images.php b/examples/tv/api/tv/images.php
index 7208242c..57f0ea51 100644
--- a/examples/tv/api/tv/images.php
+++ b/examples/tv/api/tv/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getImages(1396);
var_dump($result);
diff --git a/examples/tv/api/tv/latest.php b/examples/tv/api/tv/latest.php
index 75f412dc..9587cff9 100644
--- a/examples/tv/api/tv/latest.php
+++ b/examples/tv/api/tv/latest.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$tvShow = $client->getTvApi()->getLatest();
var_dump($tvShow);
diff --git a/examples/tv/api/tv/on_the_air.php b/examples/tv/api/tv/on_the_air.php
index 9a6047d1..f4bbb683 100644
--- a/examples/tv/api/tv/on_the_air.php
+++ b/examples/tv/api/tv/on_the_air.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getOnTheAir();
var_dump($result);
diff --git a/examples/tv/api/tv/popular.php b/examples/tv/api/tv/popular.php
index df28c88e..253ab72c 100644
--- a/examples/tv/api/tv/popular.php
+++ b/examples/tv/api/tv/popular.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getPopular();
var_dump($result);
diff --git a/examples/tv/api/tv/rate.php b/examples/tv/api/tv/rate.php
index 04fe97d7..5e41c13c 100644
--- a/examples/tv/api/tv/rate.php
+++ b/examples/tv/api/tv/rate.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Token\Session\SessionToken;
+
ini_set('display_errors', 'On');
require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
$result = $client->getTvApi()->rateTvShow(1396, 9.5);
diff --git a/examples/tv/api/tv/top_rated.php b/examples/tv/api/tv/top_rated.php
index 3773b756..a56a49ec 100644
--- a/examples/tv/api/tv/top_rated.php
+++ b/examples/tv/api/tv/top_rated.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getTopRated();
var_dump($result);
diff --git a/examples/tv/api/tv/translations.php b/examples/tv/api/tv/translations.php
index 16ca95d5..237fc9ee 100644
--- a/examples/tv/api/tv/translations.php
+++ b/examples/tv/api/tv/translations.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getTranslations(1396);
var_dump($result);
diff --git a/examples/tv/api/tv/videos.php b/examples/tv/api/tv/videos.php
index 66fcde8c..f0084845 100644
--- a/examples/tv/api/tv/videos.php
+++ b/examples/tv/api/tv/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
$result = $client->getTvApi()->getVideos(1396);
var_dump($result);
diff --git a/examples/tv/model/episode.php b/examples/tv/model/episode.php
index 0cc52b3a..1f17ba5b 100644
--- a/examples/tv/model/episode.php
+++ b/examples/tv/model/episode.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvEpisodeRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$episode = $repository->load(1396, 2, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$repository = new TvEpisodeRepository($client);
+$episode = $repository->load(1396, 2, 1);
var_dump($episode);
diff --git a/examples/tv/model/episode/account_states.php b/examples/tv/model/episode/account_states.php
index 600d3636..514c2059 100644
--- a/examples/tv/model/episode/account_states.php
+++ b/examples/tv/model/episode/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\TvEpisodeRepository;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$tvShow = $repository->getAccountStates(1396, 1, 1);
+$repository = new TvEpisodeRepository($client);
+$tvShow = $repository->getAccountStates(1396, 1, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/episode/credits.php b/examples/tv/model/episode/credits.php
index 3560e6b4..5a31a8fe 100644
--- a/examples/tv/model/episode/credits.php
+++ b/examples/tv/model/episode/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvEpisodeRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$tvShow = $repository->getCredits(1396, 1, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvEpisodeRepository($client);
+$tvShow = $repository->getCredits(1396, 1, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/episode/external_ids.php b/examples/tv/model/episode/external_ids.php
index 2c8ef730..ddee1178 100644
--- a/examples/tv/model/episode/external_ids.php
+++ b/examples/tv/model/episode/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvEpisodeRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$tvShow = $repository->getExternalIds(1396, 1, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvEpisodeRepository($client);
+$tvShow = $repository->getExternalIds(1396, 1, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/episode/images.php b/examples/tv/model/episode/images.php
index 37298d8d..b055fb55 100644
--- a/examples/tv/model/episode/images.php
+++ b/examples/tv/model/episode/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvEpisodeRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$tvShow = $repository->getImages(1396, 1, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvEpisodeRepository($client);
+$tvShow = $repository->getImages(1396, 1, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/episode/rate.php b/examples/tv/model/episode/rate.php
index 2b55f280..27067520 100644
--- a/examples/tv/model/episode/rate.php
+++ b/examples/tv/model/episode/rate.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-ini_set('display_errors','on');
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\TvEpisodeRepository;
+use Tmdb\Token\Session\SessionToken;
+
+ini_set('display_errors', 'on');
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
+$repository = new TvEpisodeRepository($client);
$rate = $repository->rate(1396, 1, 1, 9.5);
var_dump($rate);
diff --git a/examples/tv/model/episode/videos.php b/examples/tv/model/episode/videos.php
index 3f472141..ecb0b458 100644
--- a/examples/tv/model/episode/videos.php
+++ b/examples/tv/model/episode/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvEpisodeRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvEpisodeRepository($client);
-$videos = $repository->getVideos(1396, 1, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvEpisodeRepository($client);
+$videos = $repository->getVideos(1396, 1, 1);
var_dump($videos);
diff --git a/examples/tv/model/season.php b/examples/tv/model/season.php
index 5fb3b6f6..7a9505eb 100644
--- a/examples/tv/model/season.php
+++ b/examples/tv/model/season.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvSeasonRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\TvSeasonRepository($client);
-$season = $repository->load(1396, 2);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$repository = new TvSeasonRepository($client);
+$season = $repository->load(1396, 2);
var_dump($season);
diff --git a/examples/tv/model/season/credits.php b/examples/tv/model/season/credits.php
index 70edda5b..5c94de43 100644
--- a/examples/tv/model/season/credits.php
+++ b/examples/tv/model/season/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvSeasonRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvSeasonRepository($client);
-$tvShow = $repository->getCredits(1396, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvSeasonRepository($client);
+$tvShow = $repository->getCredits(1396, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/season/external_ids.php b/examples/tv/model/season/external_ids.php
index 19203b83..850faff7 100644
--- a/examples/tv/model/season/external_ids.php
+++ b/examples/tv/model/season/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvSeasonRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvSeasonRepository($client);
-$tvShow = $repository->getExternalIds(1396, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvSeasonRepository($client);
+$tvShow = $repository->getExternalIds(1396, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/season/images.php b/examples/tv/model/season/images.php
index 4e236004..caaef28b 100644
--- a/examples/tv/model/season/images.php
+++ b/examples/tv/model/season/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvSeasonRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvSeasonRepository($client);
-$tvShow = $repository->getImages(1396, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvSeasonRepository($client);
+$tvShow = $repository->getImages(1396, 1);
var_dump($tvShow);
diff --git a/examples/tv/model/season/videos.php b/examples/tv/model/season/videos.php
index 13f5d53b..0b7f5dbc 100644
--- a/examples/tv/model/season/videos.php
+++ b/examples/tv/model/season/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvSeasonRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvSeasonRepository($client);
-$videos = $repository->getVideos(1396, 1);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvSeasonRepository($client);
+$videos = $repository->getVideos(1396, 1);
var_dump($videos);
diff --git a/examples/tv/model/show.php b/examples/tv/model/show.php
index b2be9280..358ec687 100644
--- a/examples/tv/model/show.php
+++ b/examples/tv/model/show.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../vendor/autoload.php';
+require_once '../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->load(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->load(1396);
-var_dump($tvShow);
+var_dump($tvShow->getLanguages());
diff --git a/examples/tv/model/tv/account_states.php b/examples/tv/model/tv/account_states.php
index 25b56a67..23792fe7 100644
--- a/examples/tv/model/tv/account_states.php
+++ b/examples/tv/model/tv/account_states.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\TvRepository;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getAccountStates(1396);
+$repository = new TvRepository($client);
+$tvShow = $repository->getAccountStates(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/alternative_titles.php b/examples/tv/model/tv/alternative_titles.php
index 00585237..5c0519e7 100644
--- a/examples/tv/model/tv/alternative_titles.php
+++ b/examples/tv/model/tv/alternative_titles.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getAlternativeTitles(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getAlternativeTitles(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/content_ratings.php b/examples/tv/model/tv/content_ratings.php
index dff918ca..676c089f 100644
--- a/examples/tv/model/tv/content_ratings.php
+++ b/examples/tv/model/tv/content_ratings.php
@@ -9,16 +9,17 @@
* @package Tmdb
* @author Ernest Wagner
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
+use Tmdb\Repository\TvRepository;
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getContentRatings(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getContentRatings(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/credits.php b/examples/tv/model/tv/credits.php
index 89614d98..0f8685fe 100644
--- a/examples/tv/model/tv/credits.php
+++ b/examples/tv/model/tv/credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getCredits(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getCredits(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/external_ids.php b/examples/tv/model/tv/external_ids.php
index fb09fc4c..74f488bc 100644
--- a/examples/tv/model/tv/external_ids.php
+++ b/examples/tv/model/tv/external_ids.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getExternalIds(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getExternalIds(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/images.php b/examples/tv/model/tv/images.php
index bf04b60b..543bc20b 100644
--- a/examples/tv/model/tv/images.php
+++ b/examples/tv/model/tv/images.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getImages(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getImages(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/latest.php b/examples/tv/model/tv/latest.php
index 6555a568..52f47cc3 100644
--- a/examples/tv/model/tv/latest.php
+++ b/examples/tv/model/tv/latest.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getLatest();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getLatest();
var_dump($tvShow);
diff --git a/examples/tv/model/tv/on_the_air.php b/examples/tv/model/tv/on_the_air.php
index 6feac069..de12a6ec 100644
--- a/examples/tv/model/tv/on_the_air.php
+++ b/examples/tv/model/tv/on_the_air.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getOnTheAir();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getOnTheAir();
var_dump($tvShow);
diff --git a/examples/tv/model/tv/popular.php b/examples/tv/model/tv/popular.php
index 6c36281a..1974e784 100644
--- a/examples/tv/model/tv/popular.php
+++ b/examples/tv/model/tv/popular.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getPopular();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getPopular();
var_dump($tvShow);
diff --git a/examples/tv/model/tv/rate.php b/examples/tv/model/tv/rate.php
index b30060d0..d0166eb6 100644
--- a/examples/tv/model/tv/rate.php
+++ b/examples/tv/model/tv/rate.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-ini_set('display_errors','on');
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Repository\TvRepository;
+use Tmdb\Token\Session\SessionToken;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$sessionToken = new \Tmdb\SessionToken(TMDB_SESSION_TOKEN);
-$client->setSessionToken($sessionToken);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$client->getEventDispatcher()->addListener(
+ BeforeRequestEvent::class,
+ new Tmdb\Event\Listener\Request\SessionTokenRequestListener(
+ new SessionToken(TMDB_SESSION_TOKEN)
+ )
+);
-$repository = new \Tmdb\Repository\TvRepository($client);
+$repository = new TvRepository($client);
$rate = $repository->rate(1396, 9.5);
var_dump($rate);
diff --git a/examples/tv/model/tv/top_rated.php b/examples/tv/model/tv/top_rated.php
index e68a1ef6..d8b6bb34 100644
--- a/examples/tv/model/tv/top_rated.php
+++ b/examples/tv/model/tv/top_rated.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getTopRated();
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getTopRated();
var_dump($tvShow);
diff --git a/examples/tv/model/tv/translations.php b/examples/tv/model/tv/translations.php
index a94dbad4..67b828b4 100644
--- a/examples/tv/model/tv/translations.php
+++ b/examples/tv/model/tv/translations.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$tvShow = $repository->getTranslations(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$tvShow = $repository->getTranslations(1396);
var_dump($tvShow);
diff --git a/examples/tv/model/tv/videos.php b/examples/tv/model/tv/videos.php
index bbeafb77..d48dc75c 100644
--- a/examples/tv/model/tv/videos.php
+++ b/examples/tv/model/tv/videos.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../../vendor/autoload.php';
-require_once '../../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+use Tmdb\Repository\TvRepository;
+
+require_once '../../../../vendor/autoload.php';
+require_once '../../../apikey.php';
-$repository = new \Tmdb\Repository\TvRepository($client);
-$videos = $repository->getVideos(1396);
+/** @var Tmdb\Client $client * */
+$client = require_once('../../../setup-client.php');
+$repository = new TvRepository($client);
+$videos = $repository->getVideos(1396);
var_dump($videos);
diff --git a/lib/Tmdb/Api/AbstractApi.php b/lib/Tmdb/Api/AbstractApi.php
index 7fdc12bb..aba79069 100644
--- a/lib/Tmdb/Api/AbstractApi.php
+++ b/lib/Tmdb/Api/AbstractApi.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
+use JsonException;
+use Psr\Http\Message\ResponseInterface;
+use Psr\Http\Message\StreamInterface;
use Tmdb\Client;
+use Tmdb\Exception\InvalidArgumentException;
+use Tmdb\Exception\UnexpectedResponseException;
+use Tmdb\HttpClient\HttpClient;
/**
* Class AbstractApi
@@ -40,113 +48,122 @@ public function __construct(Client $client)
/**
* Send a GET request
*
- * @param string $path
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function get($path, array $parameters = [], $headers = [])
+ public function get(string $path, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->get($path, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'GET', $parameters, $headers)
+ );
}
/**
- * Send a HEAD request
+ * Send a POST request
*
- * @param $path
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param null $postBody
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function head($path, array $parameters = [], $headers = [])
+ public function post(string $path, $postBody = null, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->head($path, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'POST', $parameters, $headers, $postBody)
+ );
}
/**
- * Send a POST request
+ * Send a POST request but json_encode the post body in the request
*
- * @param string $path
- * @param null $postBody
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param mixed $postBody
+ * @param array $parameters
+ * @param array $headers
+ * @return array
+ * @throws InvalidArgumentException
*/
- public function post($path, $postBody = null, array $parameters = [], $headers = [])
+ public function postJson(string $path, $postBody = null, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->post($path, $postBody, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ try {
+ if (is_array($postBody)) {
+ $postBody = json_encode($postBody, JSON_THROW_ON_ERROR);
+ }
+
+ return $this->post($path, $postBody, $parameters, $headers);
+ } catch (JsonException $e) {
+ throw new InvalidArgumentException(
+ 'Unable to json_encode the data provided.',
+ 0,
+ $e
+ );
+ }
}
/**
- * Send a PUT request
+ * Send a HEAD request
*
- * @param $path
- * @param null $body
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function put($path, $body = null, array $parameters = [], $headers = [])
+ public function head(string $path, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->put($path, $body, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'HEAD', $parameters, $headers)
+ );
}
/**
- * Send a DELETE request
+ * Send a PUT request
*
- * @param string $path
- * @param null $body
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param null $body
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function delete($path, $body = null, array $parameters = [], $headers = [])
+ public function put(string $path, $body = null, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->delete($path, $body, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'PUT', $parameters, $headers, $body)
+ );
}
/**
- * Send a PATCH request
+ * Send a DELETE request
*
- * @param $path
- * @param null $body
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param null $body
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function patch($path, $body = null, array $parameters = [], $headers = [])
+ public function delete(string $path, $body = null, array $parameters = [], array $headers = []): array
{
- $response = $this->getClient()->getHttpClient()->patch($path, $body, $parameters, $headers);
-
- return $this->decodeResponse($response);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'DELETE', $parameters, $headers, $body)
+ );
}
/**
- * Send a POST request but json_encode the post body in the request
+ * Send a PATCH request
*
- * @param string $path
- * @param mixed $postBody
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $path
+ * @param string|null $body
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function postJson($path, $postBody = null, array $parameters = [], $headers = [])
+ public function patch(string $path, $body = null, array $parameters = [], array $headers = []): array
{
- if (is_array($postBody)) {
- $postBody = json_encode($postBody);
- }
-
- return $this->post($path, $postBody, $parameters, $headers);
+ return $this->decodeResponse(
+ $this->getHttpClient()->send($path, 'PATCH', $parameters, $headers, $body)
+ );
}
/**
@@ -159,14 +176,40 @@ public function getClient()
return $this->client;
}
+ /**
+ * Retrieve the http client
+ *
+ * @return HttpClient
+ */
+ public function getHttpClient()
+ {
+ return $this->client->getHttpClient();
+ }
+
/**
* Decode the response
*
- * @param $response
- * @return mixed
+ * @param ResponseInterface $response
+ * @return array
*/
- private function decodeResponse($response)
+ private function decodeResponse(ResponseInterface $response)
{
- return is_string($response) ? json_decode($response, true) : $response;
+ try {
+ if ($response->getBody() instanceof StreamInterface) {
+ return json_decode((string)$response->getBody(), true, 512, JSON_THROW_ON_ERROR);
+ }
+
+ return [];
+ } catch (JsonException $e) {
+ throw new UnexpectedResponseException(
+ sprintf(
+ 'Unable to decode response with body "%s", %s.',
+ (string)$response->getBody(),
+ json_last_error_msg()
+ ),
+ $response->getStatusCode(),
+ $e
+ );
+ }
}
}
diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php
index 3d1725f5..fab3670e 100644
--- a/lib/Tmdb/Api/Account.php
+++ b/lib/Tmdb/Api/Account.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,8 +24,8 @@ class Account extends AbstractApi
/**
* Get the basic information for an account. You will need to have a valid session id.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getAccount(array $parameters = [], array $headers = [])
@@ -34,9 +36,9 @@ public function getAccount(array $parameters = [], array $headers = [])
/**
* Get the lists that you have created and marked as a favorite.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getLists($accountId, array $parameters = [], array $headers = [])
@@ -47,9 +49,9 @@ public function getLists($accountId, array $parameters = [], array $headers = []
/**
* Get the list of favorite movies for an account.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getFavoriteMovies($accountId, array $parameters = [], array $headers = [])
@@ -60,9 +62,9 @@ public function getFavoriteMovies($accountId, array $parameters = [], array $hea
/**
* Get the list of favorite TV series for an account.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getFavoriteTvShows($accountId, array $parameters = [], array $headers = [])
@@ -73,27 +75,27 @@ public function getFavoriteTvShows($accountId, array $parameters = [], array $he
/**
* Add or remove a movie to an accounts favorite list.
*
- * @param integer $accountId
- * @param integer $mediaId
- * @param boolean $isFavorite
- * @param string $mediaType Either movie or tv
+ * @param int|string $accountId
+ * @param integer $mediaId
+ * @param boolean $isFavorite
+ * @param string $mediaType Either movie or tv
* @return mixed
*/
public function favorite($accountId, $mediaId, $isFavorite = true, $mediaType = 'movie')
{
return $this->postJson('account/' . $accountId . '/favorite', [
- 'media_id' => $mediaId,
+ 'media_id' => $mediaId,
'media_type' => $mediaType,
- 'favorite' => $isFavorite
+ 'favorite' => $isFavorite
]);
}
/**
* Get the list of rated movies (and associated rating) for an account.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getRatedMovies($accountId, array $parameters = [], array $headers = [])
@@ -104,9 +106,9 @@ public function getRatedMovies($accountId, array $parameters = [], array $header
/**
* Get the list of rated TV shows (and associated rating) for an account.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getRatedTvShows($accountId, array $parameters = [], array $headers = [])
@@ -117,9 +119,9 @@ public function getRatedTvShows($accountId, array $parameters = [], array $heade
/**
* Get the list of movies on an accounts watchlist.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovieWatchlist($accountId, array $parameters = [], array $headers = [])
@@ -130,9 +132,9 @@ public function getMovieWatchlist($accountId, array $parameters = [], array $hea
/**
* Get the list of TV series on an accounts watchlist.
*
- * @param integer $accountId
- * @param array $parameters
- * @param array $headers
+ * @param int|string $accountId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTvWatchlist($accountId, array $parameters = [], array $headers = [])
@@ -143,18 +145,18 @@ public function getTvWatchlist($accountId, array $parameters = [], array $header
/**
* Add or remove a movie to an accounts watch list.
*
- * @param integer $accountId
- * @param integer $mediaId
- * @param boolean $isOnWatchlist
- * @param string $mediaType Either movie or tv
+ * @param int|string $accountId
+ * @param integer $mediaId
+ * @param boolean $isOnWatchlist
+ * @param string $mediaType Either movie or tv
* @return mixed
*/
public function watchlist($accountId, $mediaId, $isOnWatchlist = true, $mediaType = 'movie')
{
return $this->postJson('account/' . $accountId . '/watchlist', [
- 'media_id' => $mediaId,
+ 'media_id' => $mediaId,
'media_type' => $mediaType,
- 'watchlist' => $isOnWatchlist
+ 'watchlist' => $isOnWatchlist
]);
}
}
diff --git a/lib/Tmdb/Api/ApiInterface.php b/lib/Tmdb/Api/ApiInterface.php
index 351c7606..d1a5ece7 100644
--- a/lib/Tmdb/Api/ApiInterface.php
+++ b/lib/Tmdb/Api/ApiInterface.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php
index 1828672d..6a0b618c 100644
--- a/lib/Tmdb/Api/Authentication.php
+++ b/lib/Tmdb/Api/Authentication.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
+use Exception;
+use InvalidArgumentException;
use Tmdb\Exception\UnauthorizedRequestTokenException;
-use Tmdb\RequestToken;
+use Tmdb\Token\Session\RequestToken;
/**
* Class Authentication
@@ -22,7 +26,7 @@
*/
class Authentication extends AbstractApi
{
- const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate';
+ public const REQUEST_TOKEN_URI = 'https://www.themoviedb.org/authenticate';
/**
* This method is used to generate a valid request token for user based authentication.
@@ -42,9 +46,10 @@ public function getNewToken()
* Redirect the user to authenticate the request token
*
* @param string $token
+ *
+ * @return void
*/
- //@codeCoverageIgnoreStart
- public function authenticateRequestToken($token)
+ public function authenticateRequestToken($token): void
{
header(sprintf(
'Location: %s/%s',
@@ -54,43 +59,21 @@ public function authenticateRequestToken($token)
}
//@codeCoverageIgnoreEnd
- /**
- * This method is used to generate a session id for user based authentication.
- * A session id is required in order to use any of the write methods.
- *
- * @param string $requestToken
- * @throws UnauthorizedRequestTokenException
- * @return mixed
- */
- public function getNewSession($requestToken)
- {
- try {
- return $this->get('authentication/session/new', ['request_token' => (string) $requestToken]);
-
- //@codeCoverageIgnoreStart
- } catch (\Exception $e) {
- if ($e->getCode() == 401) {
- throw new UnauthorizedRequestTokenException("The request token has not been validated yet.");
- }
- //@codeCoverageIgnoreEnd
- }
- }
-
/**
* Helper method to validate the request_token and obtain a session_token
*
- * @param RequestToken $requestToken
- * @param string $username
- * @param string $password
+ * @param RequestToken $requestToken
+ * @param string $username
+ * @param string $password
* @return mixed
- * @throws \InvalidArgumentException
+ * @throws InvalidArgumentException
*/
public function getSessionTokenWithLogin($requestToken, $username, $password)
{
$validatedRequestToken = $this->validateRequestTokenWithLogin($requestToken, $username, $password);
if (!$validatedRequestToken['success']) {
- throw new \InvalidArgumentException('Unable to validate the request_token, please check your credentials.');
+ throw new InvalidArgumentException('Unable to validate the request_token, please check your credentials.');
}
return $this->getNewSession($validatedRequestToken['request_token']);
@@ -100,29 +83,59 @@ public function getSessionTokenWithLogin($requestToken, $username, $password)
* This method is used to generate a session id for user based authentication.
* A session id is required in order to use any of the write methods.
*
- * @param string $requestToken
- * @param string $username
- * @param string $password
- * @throws UnauthorizedRequestTokenException
+ * @param string $requestToken
+ * @param string $username
+ * @param string $password
* @return mixed
+ * @throws UnauthorizedRequestTokenException
*/
public function validateRequestTokenWithLogin($requestToken, $username, $password)
{
try {
return $this->get('authentication/token/validate_with_login', [
- 'username' => $username,
- 'password' => $password,
- 'request_token' => (string) $requestToken
+ 'username' => $username,
+ 'password' => $password,
+ 'request_token' => (string)$requestToken
]);
- //@codeCoverageIgnoreStart
- } catch (\Exception $e) {
+ //@codeCoverageIgnoreStart
+ } catch (Exception $e) {
if ($e->getCode() == 401) {
throw new UnauthorizedRequestTokenException("The request token has not been validated yet.");
}
+
+ return null;
}
//@codeCoverageIgnoreEnd
}
+ /**
+ * This method is used to generate a session id for user based authentication.
+ * A session id is required in order to use any of the write methods.
+ *
+ * @param array|string $requestToken
+ * @return mixed
+ * @throws UnauthorizedRequestTokenException
+ */
+ public function getNewSession($requestToken)
+ {
+ try {
+ // @todo 4.0 / 4.1 verify
+ if (is_array($requestToken)) {
+ $requestToken = $requestToken['request_token'];
+ }
+ return $this->get('authentication/session/new', ['request_token' => (string)$requestToken]);
+
+ //@codeCoverageIgnoreStart
+ } catch (Exception $e) {
+ if ($e->getCode() == 401) {
+ throw new UnauthorizedRequestTokenException("The request token has not been validated yet.");
+ }
+
+ return null;
+ //@codeCoverageIgnoreEnd
+ }
+ }
+
/**
* This method is used to generate a guest session id.
*
diff --git a/lib/Tmdb/Api/Certifications.php b/lib/Tmdb/Api/Certifications.php
index 092aa16b..f7e54794 100644
--- a/lib/Tmdb/Api/Certifications.php
+++ b/lib/Tmdb/Api/Certifications.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -25,8 +27,8 @@ class Certifications extends AbstractApi
* These can be used in conjunction with the certification_country and
* certification.lte parameters when using discover.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovieList(array $parameters = [], array $headers = [])
@@ -40,8 +42,8 @@ public function getMovieList(array $parameters = [], array $headers = [])
* These can be used in conjunction with the certification_country and
* certification.lte parameters when using discover.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTvList(array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Changes.php b/lib/Tmdb/Api/Changes.php
index 9ca9b531..d9a09e81 100644
--- a/lib/Tmdb/Api/Changes.php
+++ b/lib/Tmdb/Api/Changes.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -30,8 +32,8 @@ class Changes extends AbstractApi
* Please note that the change log system to support this was changed
* on October 5, 2012 and will only show movies that have been edited since.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovieChanges(array $parameters = [], array $headers = [])
@@ -50,8 +52,8 @@ public function getMovieChanges(array $parameters = [], array $headers = [])
* Please note that the change log system to support this was changed
* on October 5, 2012 and will only show movies that have been edited since.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getPersonChanges(array $parameters = [], array $headers = [])
@@ -70,8 +72,8 @@ public function getPersonChanges(array $parameters = [], array $headers = [])
* Please note that the change log system to support this was changed
* on May 13, 2014 and will only show tv shows that have been edited since.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTvChanges(array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Collections.php b/lib/Tmdb/Api/Collections.php
index e809f886..15e1df3b 100644
--- a/lib/Tmdb/Api/Collections.php
+++ b/lib/Tmdb/Api/Collections.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -29,8 +31,8 @@ class Collections extends AbstractApi
* If you would like to sort them yourself you can use the provided release_date.
*
* @param $collection_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCollection($collection_id, array $parameters = [], array $headers = [])
@@ -42,8 +44,8 @@ public function getCollection($collection_id, array $parameters = [], array $hea
* Get all of the images for a particular collection by collection id.
*
* @param $collection_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages($collection_id, array $parameters = [], array $headers = [])
@@ -63,5 +65,4 @@ public function getTranslations($collection_id, array $parameters = [], array $h
{
return $this->get('collection/' . $collection_id . '/translations', $parameters, $headers);
}
-
}
diff --git a/lib/Tmdb/Api/Companies.php b/lib/Tmdb/Api/Companies.php
index 1c8b144d..573385fb 100644
--- a/lib/Tmdb/Api/Companies.php
+++ b/lib/Tmdb/Api/Companies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -23,8 +25,8 @@ class Companies extends AbstractApi
* This method is used to retrieve all of the basic information about a company.
*
* @param $company_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCompany($company_id, array $parameters = [], array $headers = [])
@@ -35,9 +37,9 @@ public function getCompany($company_id, array $parameters = [], array $headers =
/**
* Get the list of movies associated with a particular company.
*
- * @param integer $company_id
- * @param array $parameters
- * @param array $headers
+ * @param integer $company_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovies($company_id, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Configuration.php b/lib/Tmdb/Api/Configuration.php
index 278633bc..4a48785f 100644
--- a/lib/Tmdb/Api/Configuration.php
+++ b/lib/Tmdb/Api/Configuration.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -37,11 +39,20 @@ class Configuration extends AbstractApi
*
* http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg
*
- * @param array $headers
+ * @param array $headers
* @return mixed
*/
public function getConfiguration(array $headers = [])
{
return $this->get('configuration', [], $headers);
}
+
+ /**
+ * @param array $headers
+ * @return array
+ */
+ public function getLanguages(array $headers = []): array
+ {
+ return $this->get('configuration/languages', [], $headers);
+ }
}
diff --git a/lib/Tmdb/Api/Credits.php b/lib/Tmdb/Api/Credits.php
index 3008acc6..e08c917c 100644
--- a/lib/Tmdb/Api/Credits.php
+++ b/lib/Tmdb/Api/Credits.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -33,8 +35,8 @@ class Credits extends AbstractApi
* and are assumed to be "season regulars".
*
* @param $credit_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredit($credit_id, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Discover.php b/lib/Tmdb/Api/Discover.php
index 1d916c9b..c11cb8c3 100644
--- a/lib/Tmdb/Api/Discover.php
+++ b/lib/Tmdb/Api/Discover.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,8 +24,8 @@ class Discover extends AbstractApi
/**
* Discover movies by different types of data like average rating, number of votes, genres and certifications.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function discoverMovies(array $parameters = [], array $headers = [])
@@ -35,8 +37,8 @@ public function discoverMovies(array $parameters = [], array $headers = [])
* Discover TV shows by different types of data like average rating, number of votes, genres,
* the network they aired on and air dates.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function discoverTv(array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Find.php b/lib/Tmdb/Api/Find.php
index 7df4afb3..8d29b9b2 100644
--- a/lib/Tmdb/Api/Find.php
+++ b/lib/Tmdb/Api/Find.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -32,15 +34,15 @@ class Find extends AbstractApi
* People: imdb_id, freebase_mid, freebase_id, tvrage_id
* TV Series: imdb_id, freebase_mid, freebase_id, tvdb_id, tvrage_id
*
- * @param string $id
- * @param array $parameters
- * @param array $headers
- * @return mixed
+ * @param string $id
+ * @param array $parameters
+ * @param array $headers
+ * @return array
*/
- public function findBy($id, array $parameters = [], array $headers = [])
+ public function findBy(string $id, array $parameters = [], array $headers = []): array
{
return $this->get(
- sprintf('find/%s', $id),
+ 'find/' . $id,
$parameters,
$headers
);
diff --git a/lib/Tmdb/Api/Genres.php b/lib/Tmdb/Api/Genres.php
index 5f3d6293..2bd06155 100644
--- a/lib/Tmdb/Api/Genres.php
+++ b/lib/Tmdb/Api/Genres.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,9 +24,9 @@ class Genres extends AbstractApi
/**
* Get the list of genres, and return one by id
*
- * @param integer $id
- * @param array $parameters
- * @param array $headers
+ * @param integer $id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getGenre($id, array $parameters = [], array $headers = [])
@@ -41,8 +43,8 @@ public function getGenre($id, array $parameters = [], array $headers = [])
/**
* Get the list of genres.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getGenres(array $parameters = [], array $headers = [])
@@ -51,15 +53,15 @@ public function getGenres(array $parameters = [], array $headers = [])
$this->getMovieGenres($parameters, $headers),
$this->getTvGenres($parameters, $headers)
);
-
+
return $data;
}
/**
* Get the list of movie genres.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovieGenres(array $parameters = [], array $headers = [])
@@ -70,8 +72,8 @@ public function getMovieGenres(array $parameters = [], array $headers = [])
/**
* Get the list of TV genres.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTvGenres(array $parameters = [], array $headers = [])
@@ -80,21 +82,8 @@ public function getTvGenres(array $parameters = [], array $headers = [])
}
/**
- * Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included.
- *
- * @param $genre_id
- * @param array $parameters
- * @param array $headers
- * @return mixed
- */
- public function getMovies($genre_id, array $parameters = [], array $headers = [])
- {
- return $this->get('genre/' . $genre_id . '/movies', $parameters, $headers);
- }
-
- /**
- * @param integer $id
- * @param array $data
+ * @param integer $id
+ * @param array $data
* @return mixed
*/
private function extractGenreByIdFromResponse($id, array $data = [])
@@ -107,4 +96,17 @@ private function extractGenreByIdFromResponse($id, array $data = [])
return null;
}
+
+ /**
+ * Get the list of movies for a particular genre by id. By default, only movies with 10 or more votes are included.
+ *
+ * @param $genre_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getMovies($genre_id, array $parameters = [], array $headers = [])
+ {
+ return $this->get('genre/' . $genre_id . '/movies', $parameters, $headers);
+ }
}
diff --git a/lib/Tmdb/Api/GuestSession.php b/lib/Tmdb/Api/GuestSession.php
index 7b7b1770..6aecfec5 100644
--- a/lib/Tmdb/Api/GuestSession.php
+++ b/lib/Tmdb/Api/GuestSession.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
+
use Tmdb\Exception\MissingSessionTokenException;
-use Tmdb\SessionToken;
+use Tmdb\Token\Session\SessionToken;
/**
* Class GuestSession
@@ -24,14 +27,14 @@ class GuestSession extends AbstractApi
/**
* Get a list of rated movies for a specific guest session id.
*
- * @param array $parameters
- * @param array $headers
- * @throws MissingSessionTokenException when the guest session token was not set on the client.
+ * @param array $parameters
+ * @param array $headers
* @return mixed
+ * @throws MissingSessionTokenException when the guest session token was not set on the client.
*/
public function getRatedMovies(array $parameters = [], array $headers = [])
{
- $sessionToken = $this->client->getSessionToken();
+ $sessionToken = $this->client->getGuestSessionToken();
if (!$sessionToken instanceof SessionToken) {
throw new MissingSessionTokenException('The guest session token was not set on the client.');
diff --git a/lib/Tmdb/Api/Jobs.php b/lib/Tmdb/Api/Jobs.php
index dd6c5f90..7dad85ef 100644
--- a/lib/Tmdb/Api/Jobs.php
+++ b/lib/Tmdb/Api/Jobs.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,8 +24,8 @@ class Jobs extends AbstractApi
/**
* Get a list of valid jobs.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getJobs(array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Keywords.php b/lib/Tmdb/Api/Keywords.php
index d2b2c7ee..4c04f2a7 100644
--- a/lib/Tmdb/Api/Keywords.php
+++ b/lib/Tmdb/Api/Keywords.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,9 +24,9 @@ class Keywords extends AbstractApi
/**
* Get the basic information for a specific keyword id.
*
- * @param int $keyword_id
- * @param array $parameters
- * @param array $headers
+ * @param int $keyword_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getKeyword($keyword_id, array $parameters = [], array $headers = [])
@@ -35,9 +37,9 @@ public function getKeyword($keyword_id, array $parameters = [], array $headers =
/**
* Get the list of movies for a particular keyword by id.
*
- * @param int $keyword_id
- * @param array $parameters
- * @param array $headers
+ * @param int $keyword_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovies($keyword_id, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php
index c2bb797e..b6dcf4c4 100644
--- a/lib/Tmdb/Api/Lists.php
+++ b/lib/Tmdb/Api/Lists.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,9 +24,9 @@ class Lists extends AbstractApi
/**
* Get a list by id.
*
- * @param string $list_id
- * @param array $parameters
- * @param array $headers
+ * @param string $list_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getList($list_id, array $parameters = [], array $headers = [])
@@ -35,10 +37,10 @@ public function getList($list_id, array $parameters = [], array $headers = [])
/**
* This method lets users create a new list. A valid session id is required.
*
- * @param string $name
- * @param string $description
- * @param array $parameters
- * @param array $headers
+ * @param string $name
+ * @param string $description
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function createList($name, $description, array $parameters = [], array $headers = [])
@@ -49,10 +51,10 @@ public function createList($name, $description, array $parameters = [], array $h
/**
* Check to see if a movie ID is already added to a list.
*
- * @param string $id
- * @param int $movieId
- * @param array $parameters
- * @param array $headers
+ * @param string $id
+ * @param int $movieId
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getItemStatus($id, $movieId, array $parameters = [], array $headers = [])
@@ -67,8 +69,8 @@ public function getItemStatus($id, $movieId, array $parameters = [], array $head
/**
* This method lets users add new movies to a list that they created. A valid session id is required.
*
- * @param string $id
- * @param string $mediaId
+ * @param string $id
+ * @param string|int $mediaId
* @return mixed
*/
public function addMediaToList($id, $mediaId)
@@ -79,8 +81,8 @@ public function addMediaToList($id, $mediaId)
/**
* This method lets users delete movies from a list that they created. A valid session id is required.
*
- * @param string $id
- * @param string $mediaId
+ * @param string $id
+ * @param string|int $mediaId
* @return mixed
*/
public function removeMediaFromList($id, $mediaId)
@@ -91,7 +93,7 @@ public function removeMediaFromList($id, $mediaId)
/**
* This method lets users delete a list that they created. A valid session id is required.
*
- * @param string $id
+ * @param string $id
* @return mixed
*/
public function deleteList($id)
@@ -105,16 +107,16 @@ public function deleteList($id)
* This is a irreversible action and should be treated with caution.
* A valid session id is required.
*
- * @param string $id
- * @param boolean $confirm
+ * @param string $id
+ * @param boolean $confirm
* @return mixed
*/
public function clearList($id, $confirm)
{
return $this->post(
- 'list/'.$id.'/clear',
+ 'list/' . $id . '/clear',
null,
- ['confirm' => (bool) $confirm === true ? 'true':'false']
+ ['confirm' => (bool)$confirm === true ? 'true' : 'false']
);
}
}
diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php
index 5c3eccb4..b7b139d5 100644
--- a/lib/Tmdb/Api/Movies.php
+++ b/lib/Tmdb/Api/Movies.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -23,8 +25,8 @@ class Movies extends AbstractApi
* Get the basic movie information for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getMovie($movie_id, array $parameters = [], array $headers = [])
@@ -36,8 +38,8 @@ public function getMovie($movie_id, array $parameters = [], array $headers = [])
* Get the alternative titles for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getAlternativeTitles($movie_id, array $parameters = [], array $headers = [])
@@ -49,8 +51,8 @@ public function getAlternativeTitles($movie_id, array $parameters = [], array $h
* Get the cast and crew information for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredits($movie_id, array $parameters = [], array $headers = [])
@@ -62,8 +64,8 @@ public function getCredits($movie_id, array $parameters = [], array $headers = [
* Get the images (posters and backdrops) for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages($movie_id, array $parameters = [], array $headers = [])
@@ -75,8 +77,8 @@ public function getImages($movie_id, array $parameters = [], array $headers = []
* Get the plot keywords for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getKeywords($movie_id, array $parameters = [], array $headers = [])
@@ -88,8 +90,8 @@ public function getKeywords($movie_id, array $parameters = [], array $headers =
* Get the release date by country for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getReleases($movie_id, array $parameters = [], array $headers = [])
@@ -100,11 +102,11 @@ public function getReleases($movie_id, array $parameters = [], array $headers =
/**
* Get the trailers for a specific movie id.
*
- * @deprecated TMDB changed the way of requesting trailers, see getVideos instead!
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
+ * @deprecated TMDB changed the way of requesting trailers, see getVideos instead!
*/
public function getTrailers($movie_id, array $parameters = [], array $headers = [])
{
@@ -115,8 +117,8 @@ public function getTrailers($movie_id, array $parameters = [], array $headers =
* Get the translations for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTranslations($movie_id, array $parameters = [], array $headers = [])
@@ -128,8 +130,8 @@ public function getTranslations($movie_id, array $parameters = [], array $header
* Get the similar movies for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getSimilar($movie_id, array $parameters = [], array $headers = [])
@@ -141,8 +143,8 @@ public function getSimilar($movie_id, array $parameters = [], array $headers = [
* Get the recommended movies for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getRecommendations($movie_id, array $parameters = [], array $headers = [])
@@ -154,8 +156,8 @@ public function getRecommendations($movie_id, array $parameters = [], array $hea
* Get the reviews for a particular movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getReviews($movie_id, array $parameters = [], array $headers = [])
@@ -167,8 +169,8 @@ public function getReviews($movie_id, array $parameters = [], array $headers = [
* Get the lists that the movie belongs to.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getLists($movie_id, array $parameters = [], array $headers = [])
@@ -180,8 +182,8 @@ public function getLists($movie_id, array $parameters = [], array $headers = [])
* Get the changes for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getChanges($movie_id, array $parameters = [], array $headers = [])
@@ -192,8 +194,8 @@ public function getChanges($movie_id, array $parameters = [], array $headers = [
/**
* Get the latest movie id.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getLatest(array $parameters = [], array $headers = [])
@@ -205,8 +207,8 @@ public function getLatest(array $parameters = [], array $headers = [])
* Get the list of upcoming movies. This list refreshes every day.
* The maximum number of items this list will include is 100.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getUpcoming(array $parameters = [], array $headers = [])
@@ -218,8 +220,8 @@ public function getUpcoming(array $parameters = [], array $headers = [])
* Get the list of movies playing in theatres. This list refreshes every day.
* The maximum number of items this list will include is 100.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getNowPlaying(array $parameters = [], array $headers = [])
@@ -231,8 +233,8 @@ public function getNowPlaying(array $parameters = [], array $headers = [])
* Get the list of popular movies on The Movie Database.
* This list refreshes every day.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getPopular(array $parameters = [], array $headers = [])
@@ -244,8 +246,8 @@ public function getPopular(array $parameters = [], array $headers = [])
* Get the list of top rated movies. By default, this list will only include
* movies that have 10 or more votes. This list refreshes every day.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTopRated(array $parameters = [], array $headers = [])
@@ -259,7 +261,7 @@ public function getTopRated(array $parameters = [], array $headers = [])
*
* A valid session id is required.
*
- * @param integer $id
+ * @param integer $id
* @return mixed
*/
public function getAccountStates($id)
@@ -272,25 +274,51 @@ public function getAccountStates($id)
*
* A valid session id or guest session id is required.
*
- * @param integer $id
- * @param double $rating
+ * @param integer $id
+ * @param double $rating
* @return mixed
*/
public function rateMovie($id, $rating)
{
- return $this->postJson('movie/' . $id . '/rating', ['value' => (float) $rating]);
+ return $this->postJson('movie/' . $id . '/rating', ['value' => (float)$rating]);
}
/**
* Get the videos (trailers, teasers, clips, etc...) for a specific movie id.
*
* @param $movie_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getVideos($movie_id, array $parameters = [], array $headers = [])
{
return $this->get('movie/' . $movie_id . '/videos', $parameters, $headers);
}
+
+ /**
+ * Get the watch providers (by region) for a specific movie id.
+ *
+ * @param $movie_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getWatchProviders($movie_id, array $parameters = [], array $headers = [])
+ {
+ return $this->get('movie/' . $movie_id . '/watch/providers', $parameters, $headers);
+ }
+
+ /**
+ * Get the external ids that we have stored for a movie.
+ *
+ * @param $movie_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getExternalIds($movie_id, array $parameters = [], array $headers = [])
+ {
+ return $this->get('movie/' . $movie_id . '/external_ids', $parameters, $headers);
+ }
}
diff --git a/lib/Tmdb/Api/Networks.php b/lib/Tmdb/Api/Networks.php
index a6d29618..c0038caa 100644
--- a/lib/Tmdb/Api/Networks.php
+++ b/lib/Tmdb/Api/Networks.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -25,9 +27,9 @@ class Networks extends AbstractApi
* You can use this ID to search for TV shows with the discover.
* At this time we don't have much but this will be fleshed out over time.
*
- * @param int $network_id
- * @param array $parameters
- * @param array $headers
+ * @param int $network_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getNetwork($network_id, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php
index acf75d0d..93c61039 100644
--- a/lib/Tmdb/Api/People.php
+++ b/lib/Tmdb/Api/People.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -23,8 +25,8 @@ class People extends AbstractApi
* Get the general person information for a specific id.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getPerson($person_id, array $parameters = [], array $headers = [])
@@ -36,8 +38,8 @@ public function getPerson($person_id, array $parameters = [], array $headers = [
* Get the credits for a specific person id.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredits($person_id, array $parameters = [], array $headers = [])
@@ -46,56 +48,56 @@ public function getCredits($person_id, array $parameters = [], array $headers =
}
/**
- * Get the movie credits for a specific person id.
+ * Get the combined (movie and TV) credits for a specific person id.
+ *
+ * To get the expanded details for each TV record, call the /credit method with the provided credit_id.
+ * This will provide details about which episode and/or season the credit is for.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
- public function getMovieCredits($person_id, array $parameters = [], array $headers = [])
+ public function getCombinedCredits($person_id, array $parameters = [], array $headers = [])
{
- return $this->get('person/' . $person_id . '/movie_credits', $parameters, $headers);
+ return $this->get('person/' . $person_id . '/combined_credits', $parameters, $headers);
}
/**
- * Get the TV credits for a specific person id.
- *
- * To get the expanded details for each record, call the /credit method with the provided credit_id.
- * This will provide details about which episode and/or season the credit is for.
+ * Get the movie credits for a specific person id.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
- public function getTvCredits($person_id, array $parameters = [], array $headers = [])
+ public function getMovieCredits($person_id, array $parameters = [], array $headers = [])
{
- return $this->get('person/' . $person_id . '/tv_credits', $parameters, $headers);
+ return $this->get('person/' . $person_id . '/movie_credits', $parameters, $headers);
}
/**
- * Get the combined (movie and TV) credits for a specific person id.
+ * Get the TV credits for a specific person id.
*
- * To get the expanded details for each TV record, call the /credit method with the provided credit_id.
+ * To get the expanded details for each record, call the /credit method with the provided credit_id.
* This will provide details about which episode and/or season the credit is for.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
- public function getCombinedCredits($person_id, array $parameters = [], array $headers = [])
+ public function getTvCredits($person_id, array $parameters = [], array $headers = [])
{
- return $this->get('person/' . $person_id . '/combined_credits', $parameters, $headers);
+ return $this->get('person/' . $person_id . '/tv_credits', $parameters, $headers);
}
/**
* Get the images for a specific person id.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages($person_id, array $parameters = [], array $headers = [])
@@ -113,8 +115,8 @@ public function getImages($person_id, array $parameters = [], array $headers = [
* The language is present on fields that are translatable.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getChanges($person_id, array $parameters = [], array $headers = [])
@@ -126,8 +128,8 @@ public function getChanges($person_id, array $parameters = [], array $headers =
* Get the external ids for a specific person id.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getExternalIds($person_id, array $parameters = [], array $headers = [])
@@ -141,8 +143,8 @@ public function getExternalIds($person_id, array $parameters = [], array $header
* We return all of the image results with a media object mapped for each image.
*
* @param $person_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTaggedImages($person_id, array $parameters = [], array $headers = [])
@@ -153,8 +155,8 @@ public function getTaggedImages($person_id, array $parameters = [], array $heade
/**
* Get the list of popular people on The Movie Database. This list refreshes every day.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getPopular(array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Reviews.php b/lib/Tmdb/Api/Reviews.php
index 31204411..a1f925ce 100644
--- a/lib/Tmdb/Api/Reviews.php
+++ b/lib/Tmdb/Api/Reviews.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -23,8 +25,8 @@ class Reviews extends AbstractApi
* Get the full details of a review by ID.
*
* @param $review_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getReview($review_id, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php
index 0c5b9c5e..d48dcad7 100644
--- a/lib/Tmdb/Api/Search.php
+++ b/lib/Tmdb/Api/Search.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,9 +24,9 @@ class Search extends AbstractApi
/**
* Search for movies by title.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchMovies($query, array $parameters = [], array $headers = [])
@@ -37,9 +39,9 @@ public function searchMovies($query, array $parameters = [], array $headers = []
/**
* Search for collections by name.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchCollection($query, array $parameters = [], array $headers = [])
@@ -52,9 +54,9 @@ public function searchCollection($query, array $parameters = [], array $headers
/**
* Search for TV shows by title.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchTv($query, array $parameters = [], array $headers = [])
@@ -67,9 +69,9 @@ public function searchTv($query, array $parameters = [], array $headers = [])
/**
* Search for people by name.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchPersons($query, array $parameters = [], array $headers = [])
@@ -79,30 +81,15 @@ public function searchPersons($query, array $parameters = [], array $headers = [
], $headers));
}
- /**
- * Search for lists by name and description.
- *
- * @param string $query
- * @param array $parameters
- * @param array $headers
- * @return mixed
- */
- public function searchList($query, array $parameters = [], array $headers = [])
- {
- return $this->get('search/list', array_merge($parameters, [
- 'query' => $query
- ], $headers));
- }
-
/**
* Search for companies by name.
*
* @param $query
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
- public function searchCompany($query, array $parameters = [], array $headers = [])
+ public function searchCompany(string $query, array $parameters = [], array $headers = [])
{
return $this->get('search/company', array_merge($parameters, [
'query' => $query
@@ -112,9 +99,9 @@ public function searchCompany($query, array $parameters = [], array $headers = [
/**
* Search for companies by name.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchKeyword($query, array $parameters = [], array $headers = [])
@@ -130,9 +117,9 @@ public function searchKeyword($query, array $parameters = [], array $headers = [
* Each item returned in the result array has a media_type field that maps to either movie, tv or person.
* Each mapped result is the same response you would get from each independent search.
*
- * @param string $query
- * @param array $parameters
- * @param array $headers
+ * @param string $query
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function searchMulti($query, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/Api/Timezones.php b/lib/Tmdb/Api/Timezones.php
index 9fc96513..b015eb86 100644
--- a/lib/Tmdb/Api/Timezones.php
+++ b/lib/Tmdb/Api/Timezones.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php
index 50d1c748..ab6f0af3 100644
--- a/lib/Tmdb/Api/Tv.php
+++ b/lib/Tmdb/Api/Tv.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -22,9 +24,9 @@ class Tv extends AbstractApi
/**
* Get the primary information about a TV series by id.
*
- * @param integer $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param integer $tvshow_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTvshow($tvshow_id, array $parameters = [], array $headers = [])
@@ -37,8 +39,8 @@ public function getTvshow($tvshow_id, array $parameters = [], array $headers = [
* Just like the website, we pull this information from the last season of the series.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredits($tvshow_id, array $parameters = [], array $headers = [])
@@ -46,25 +48,24 @@ public function getCredits($tvshow_id, array $parameters = [], array $headers =
return $this->get('tv/' . $tvshow_id . '/credits', $parameters, $headers);
}
- /**
- * Get the content ratings for a specific TV show id.
-
- * @param $tvshow_id
- * @param array $parameters
- * @param array $headers
- * @return mixed
- */
+ /**
+ * Get the content ratings for a specific TV show id.
+ * @param $tvshow_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
public function getContentRatings($tvshow_id, array $parameters = [], array $headers = [])
{
- return $this->get('tv/' . $tvshow_id . '/content_ratings', $parameters, $headers);
+ return $this->get('tv/' . $tvshow_id . '/content_ratings', $parameters, $headers);
}
/**
* Get the external ids that we have stored for a TV series.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getExternalIds($tvshow_id, array $parameters = [], array $headers = [])
@@ -76,8 +77,8 @@ public function getExternalIds($tvshow_id, array $parameters = [], array $header
* Get the images (posters and backdrops) for a TV series.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages($tvshow_id, array $parameters = [], array $headers = [])
@@ -88,8 +89,8 @@ public function getImages($tvshow_id, array $parameters = [], array $headers = [
/**
* Get the list of popular TV shows. This list refreshes every day.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getPopular(array $parameters = [], array $headers = [])
@@ -103,8 +104,8 @@ public function getPopular(array $parameters = [], array $headers = [])
* By default, this list will only include TV shows that have 2 or more votes.
* This list refreshes every day.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTopRated(array $parameters = [], array $headers = [])
@@ -117,9 +118,9 @@ public function getTopRated(array $parameters = [], array $headers = [])
*
* These translations cascade down to the episode level.
*
- * @param int $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param int $tvshow_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getTranslations($tvshow_id, array $parameters = [], array $headers = [])
@@ -132,8 +133,8 @@ public function getTranslations($tvshow_id, array $parameters = [], array $heade
*
* This query looks for any TV show that has an episode with an air date in the next 7 days.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getOnTheAir(array $parameters = [], array $headers = [])
@@ -146,8 +147,8 @@ public function getOnTheAir(array $parameters = [], array $headers = [])
*
* Without a specified timezone, this query defaults to EST (Eastern Time UTC-05:00).
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getAiringToday(array $parameters = [], array $headers = [])
@@ -158,9 +159,9 @@ public function getAiringToday(array $parameters = [], array $headers = [])
/**
* Get the videos that have been added to a TV series (trailers, opening credits, etc...)
*
- * @param int $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param int $tvshow_id
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getVideos($tvshow_id, array $parameters = [], array $headers = [])
@@ -168,6 +169,19 @@ public function getVideos($tvshow_id, array $parameters = [], array $headers = [
return $this->get('tv/' . $tvshow_id . '/videos', $parameters, $headers);
}
+ /**
+ * Get the watch providers (by region) for a specific movie id.
+ *
+ * @param $movie_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getWatchProviders($tvshow_id, array $parameters = [], array $headers = [])
+ {
+ return $this->get('tv/' . $tvshow_id . '/watch/providers', $parameters, $headers);
+ }
+
/**
* Get the changes for a specific TV show id.
*
@@ -183,8 +197,8 @@ public function getVideos($tvshow_id, array $parameters = [], array $headers = [
* You can use the /tv/season/{id}/changes and /tv/episode/{id}/changes methods to look up these specific changes.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getChanges($tvshow_id, array $parameters = [], array $headers = [])
@@ -195,8 +209,8 @@ public function getChanges($tvshow_id, array $parameters = [], array $headers =
/**
* Get the latest TV show id.
*
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getLatest(array $parameters = [], array $headers = [])
@@ -208,8 +222,8 @@ public function getLatest(array $parameters = [], array $headers = [])
* Get the plot keywords for a specific TV show id.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getKeywords($tvshow_id, array $parameters = [], array $headers = [])
@@ -221,8 +235,8 @@ public function getKeywords($tvshow_id, array $parameters = [], array $headers =
* Get the similar TV shows for a specific tv id.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getSimilar($tvshow_id, array $parameters = [], array $headers = [])
@@ -234,8 +248,8 @@ public function getSimilar($tvshow_id, array $parameters = [], array $headers =
* Get the recommended TV shows for a specific tv id.
*
* @param $tvshow_id
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getRecommendations($tvshow_id, array $parameters = [], array $headers = [])
@@ -249,7 +263,7 @@ public function getRecommendations($tvshow_id, array $parameters = [], array $he
*
* A valid session id is required.
*
- * @param integer $id
+ * @param integer $id
* @return mixed
*/
public function getAccountStates($id)
@@ -262,23 +276,36 @@ public function getAccountStates($id)
*
* A valid session id or guest session id is required.
*
- * @param integer $id
- * @param double $rating
+ * @param integer $id
+ * @param double $rating
* @return mixed
*/
public function rateTvShow($id, $rating)
{
- return $this->postJson('tv/' . $id . '/rating', ['value' => (float) $rating]);
+ return $this->postJson('tv/' . $id . '/rating', ['value' => (float)$rating]);
+ }
+
+ /**
+ * Get the alternative titles for a specific show ID.
+ *
+ * @param integer $id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getAlternativeTitles($id, array $parameters = [], array $headers = [])
+ {
+ return $this->get('tv/' . $id . '/alternative_titles', $parameters, $headers);
}
/**
* Get the alternative titles for a specific show ID.
*
- * @param integer $id
+ * @param integer $id
* @return mixed
*/
- public function getAlternativeTitles($id)
+ public function getEpisodeGroups($id)
{
- return $this->get('tv/' . $id . '/alternative_titles');
+ return $this->get('tv/' . $id . '/episode_groups');
}
}
diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php
index e6d8cf6d..02b764a6 100644
--- a/lib/Tmdb/Api/TvEpisode.php
+++ b/lib/Tmdb/Api/TvEpisode.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -25,8 +27,8 @@ class TvEpisode extends AbstractApi
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getEpisode(
@@ -54,8 +56,8 @@ public function getEpisode(
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredits(
@@ -83,8 +85,8 @@ public function getCredits(
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getExternalIds(
@@ -112,8 +114,8 @@ public function getExternalIds(
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages(
@@ -135,14 +137,41 @@ public function getImages(
);
}
+ /**
+ * Get the list of translations that exist for a TV episode.
+ *
+ * @param int $tvshow_id
+ * @param array $parameters
+ * @param array $headers
+ * @return mixed
+ */
+ public function getTranslations(
+ $tvshow_id,
+ $season_number,
+ $episode_number,
+ array $parameters = [],
+ array $headers = []
+ ) {
+ return $this->get(
+ sprintf(
+ 'tv/%s/season/%s/episode/%s/translations',
+ $tvshow_id,
+ $season_number,
+ $episode_number
+ ),
+ $parameters,
+ $headers
+ );
+ }
+
/**
* Get the videos that have been added to a TV episode (teasers, clips, etc...)
*
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getVideos(
@@ -173,8 +202,8 @@ public function getVideos(
* @param $tvshow_id
* @param $season_number
* @param $episode_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getChanges(
@@ -247,8 +276,7 @@ public function rateTvEpisode(
$season_number,
$episode_number
),
- ['value' => (float) $rating]
+ ['value' => (float)$rating]
);
}
-
}
diff --git a/lib/Tmdb/Api/TvEpisodeGroup.php b/lib/Tmdb/Api/TvEpisodeGroup.php
new file mode 100644
index 00000000..76b111e2
--- /dev/null
+++ b/lib/Tmdb/Api/TvEpisodeGroup.php
@@ -0,0 +1,46 @@
+get(
+ sprintf(
+ 'tv/episode_group/%s',
+ $episode_group
+ ),
+ $parameters,
+ $headers
+ );
+ }
+}
diff --git a/lib/Tmdb/Api/TvSeason.php b/lib/Tmdb/Api/TvSeason.php
index 2586ce93..61ebad47 100644
--- a/lib/Tmdb/Api/TvSeason.php
+++ b/lib/Tmdb/Api/TvSeason.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Api;
/**
@@ -24,11 +26,11 @@ class TvSeason extends AbstractApi
*
* @param $tvshow_id
* @param $season_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
- public function getSeason($tvshow_id, $season_number, array $parameters = [], array $headers = [])
+ public function getSeason(int $tvshow_id, int $season_number, array $parameters = [], array $headers = [])
{
return $this->get(sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $parameters, $headers);
}
@@ -38,8 +40,8 @@ public function getSeason($tvshow_id, $season_number, array $parameters = [], ar
*
* @param $tvshow_id
* @param $season_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getCredits($tvshow_id, $season_number, array $parameters = [], array $headers = [])
@@ -52,8 +54,8 @@ public function getCredits($tvshow_id, $season_number, array $parameters = [], a
*
* @param $tvshow_id
* @param $season_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getExternalIds($tvshow_id, $season_number, array $parameters = [], array $headers = [])
@@ -66,8 +68,8 @@ public function getExternalIds($tvshow_id, $season_number, array $parameters = [
*
* @param $tvshow_id
* @param $season_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getImages($tvshow_id, $season_number, array $parameters = [], array $headers = [])
@@ -80,8 +82,8 @@ public function getImages($tvshow_id, $season_number, array $parameters = [], ar
*
* @param $tvshow_id
* @param $season_number
- * @param array $parameters
- * @param array $headers
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getVideos($tvshow_id, $season_number, array $parameters = [], array $headers = [])
@@ -95,10 +97,10 @@ public function getVideos($tvshow_id, $season_number, array $parameters = [], ar
*
* This method uses the season_id value found in the change entries.
*
- * @param integer $tvshow_id
- * @param integer $season_number
- * @param array $parameters
- * @param array $headers
+ * @param integer $tvshow_id
+ * @param integer $season_number
+ * @param array $parameters
+ * @param array $headers
* @return mixed
*/
public function getChanges($tvshow_id, $season_number, array $parameters = [], array $headers = [])
diff --git a/lib/Tmdb/ApiMethodsTrait.php b/lib/Tmdb/ApiMethodsTrait.php
index 52a3b0b8..aed724ae 100644
--- a/lib/Tmdb/ApiMethodsTrait.php
+++ b/lib/Tmdb/ApiMethodsTrait.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb;
trait ApiMethodsTrait
@@ -205,4 +207,12 @@ public function getTvEpisodeApi()
{
return new Api\TvEpisode($this);
}
+
+ /**
+ * @return Api\TvEpisodeGroup
+ */
+ public function getTvEpisodeGroupApi()
+ {
+ return new Api\TvEpisodeGroup($this);
+ }
}
diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php
index 498bdab2..36468168 100644
--- a/lib/Tmdb/Client.php
+++ b/lib/Tmdb/Client.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 2.1.10
+ * @version 4.0.0
*/
+
namespace Tmdb;
-use Doctrine\Common\Cache\FilesystemCache;
-use Monolog\Handler\StreamHandler;
-use Psr\Log\LogLevel;
-use Symfony\Component\EventDispatcher\EventDispatcher;
+use Http\Discovery\Psr17FactoryDiscovery;
+use Http\Discovery\Psr18ClientDiscovery;
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Psr\Http\Client\ClientInterface;
+use Psr\Http\Message\RequestFactoryInterface;
+use Psr\Http\Message\ResponseFactoryInterface;
+use Psr\Http\Message\StreamFactoryInterface;
+use Psr\Http\Message\UriFactoryInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
-use Tmdb\HttpClient\Adapter\AdapterInterface;
-use Tmdb\HttpClient\Adapter\GuzzleAdapter;
use Tmdb\HttpClient\HttpClient;
-use Tmdb\ApiToken as Token;
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Api\BearerToken;
+use Tmdb\Token\Session\GuestSessionToken;
+use Tmdb\Token\Session\SessionBearerToken;
+use Tmdb\Token\Session\SessionToken;
/**
* Client wrapper for TMDB
@@ -31,16 +39,16 @@ class Client
use ApiMethodsTrait;
/** Client Version */
- const VERSION = '2.1.10';
+ public const VERSION = '4.0.0';
/** Base API URI */
- const TMDB_URI = 'api.themoviedb.org/3/';
+ public const TMDB_URI = 'api.themoviedb.org/3';
/** Insecure schema */
- const SCHEME_INSECURE = 'http';
+ public const SCHEME_INSECURE = 'http';
/** Secure schema */
- const SCHEME_SECURE = 'https';
+ public const SCHEME_SECURE = 'https';
/**
* Stores the HTTP Client
@@ -59,286 +67,227 @@ class Client
/**
* Construct our client
*
- * @param ApiToken $token
- * @param array $options
+ * @param ConfigurationInterface|array $options
*/
- public function __construct(ApiToken $token, $options = [])
+ public function __construct($options = [])
{
if ($options instanceof ConfigurationInterface) {
$options = $options->all();
}
- $this->configureOptions(array_replace(['token' => $token], (array) $options));
- $this->constructHttpClient();
+ $this->configureOptions($options);
}
/**
- * @param SessionToken $sessionToken
- * @return $this
+ * Configure options
+ *
+ * @param array $options
+ * @return array
*/
- public function setSessionToken($sessionToken)
+ protected function configureOptions(array $options)
{
- $this->options['session_token'] = $sessionToken;
- $this->reconstructHttpClient();
+ $resolver = new OptionsResolver();
- return $this;
- }
+ $resolver->setDefaults(
+ [
+ 'secure' => true,
+ 'host' => self::TMDB_URI,
+ 'base_uri' => null,
+ 'api_token' => null,
+ 'guest_session_token' => null,
+ 'http' => function (OptionsResolver $optionsResolver) {
+ $optionsResolver->setDefaults(
+ [
+ 'client' => null,
+ 'request_factory' => null,
+ 'response_factory' => null,
+ 'stream_factory' => null,
+ 'uri_factory' => null,
+ ]
+ );
+ $optionsResolver->setRequired(
+ [
+ 'client',
+ 'request_factory',
+ 'response_factory',
+ 'stream_factory',
+ 'uri_factory'
+ ]
+ );
+ $optionsResolver->setAllowedTypes('client', [ClientInterface::class, 'null']);
+ $optionsResolver->setAllowedTypes('request_factory', [RequestFactoryInterface::class, 'null']);
+ $optionsResolver->setAllowedTypes('response_factory', [ResponseFactoryInterface::class, 'null']);
+ $optionsResolver->setAllowedTypes('stream_factory', [StreamFactoryInterface::class, 'null']);
+ $optionsResolver->setAllowedTypes('uri_factory', [UriFactoryInterface::class, 'null']);
+ },
+ 'hydration' => function (OptionsResolver $optionsResolver) {
+ $optionsResolver->setDefaults(
+ [
+ 'event_listener_handles_hydration' => false,
+ 'only_for_specified_models' => []
+ ]
+ );
+ $optionsResolver->setAllowedTypes('event_listener_handles_hydration', ['bool']);
+ // @todo 4.1 validate these are actually models
+ $optionsResolver->setAllowedTypes('only_for_specified_models', ['array']);
+ },
+ 'event_dispatcher' => function (OptionsResolver $optionsResolver) {
+ $optionsResolver->setDefaults(
+ [
+ 'adapter' => null
+ ]
+ );
+
+ $optionsResolver->setRequired(['adapter']);
+ $optionsResolver->setAllowedTypes('adapter', [EventDispatcherInterface::class]);
+ }
+ ]
+ );
- /**
- * @return SessionToken
- */
- public function getSessionToken()
- {
- return $this->options['session_token'];
- }
+ $resolver->setRequired(
+ [
+ 'host',
+ 'api_token',
+ 'secure',
+ 'http',
+ 'event_dispatcher',
+ ]
+ );
- /**
- * Get the API token
- *
- * @return Token
- */
- public function getToken()
- {
- return $this->options['token'];
- }
+ $resolver->setAllowedTypes('host', ['string']);
- /**
- * @param HttpClient $httpClient
- */
- public function setHttpClient(HttpClient $httpClient)
- {
- $this->httpClient = $httpClient;
- }
+ // @todo 4.1 fix smelly stuff
+ $resolver->setAllowedTypes('api_token', [ApiToken::class, BearerToken::class]);
+ $resolver->setAllowedTypes('secure', ['bool']);
+ $resolver->setAllowedTypes('http', ['array']);
+ $resolver->setAllowedTypes('event_dispatcher', ['array']);
+
+ // @todo 4.1 fix smelly stuff
+ $resolver->setAllowedTypes(
+ 'guest_session_token',
+ [
+ GuestSessionToken::class,
+ SessionBearerToken::class,
+ 'null'
+ ]
+ );
- /**
- * @return HttpClient
- */
- public function getHttpClient()
- {
- return $this->httpClient;
- }
+ if (is_string($options['api_token'])) {
+ $options['api_token'] = new ApiToken($options['api_token']);
+ }
- /**
- * Get the adapter
- *
- * @return AdapterInterface
- */
- public function getAdapter()
- {
- return $this->options['adapter'];
- }
+ $this->options = $this->postResolve(
+ $resolver->resolve($options)
+ );
- /**
- * Get the event dispatcher
- *
- * @return AdapterInterface
- */
- public function getEventDispatcher()
- {
- return $this->options['event_dispatcher'];
- }
+ $this->httpClient = new HttpClient(
+ [
+ 'http' => $this->options['http'],
+ 'event_dispatcher' => $this->options['event_dispatcher'],
+ 'base_uri' => $this->options['base_uri'],
+ 'hydration' => $this->options['hydration']
+ ]
+ );
- /**
- * @return array
- */
- public function getOptions()
- {
return $this->options;
}
/**
- * @param string $key
+ * Post resolve
*
+ * @param array $options
* @return array
*/
- public function getOption($key)
+ protected function postResolve(array $options = []): array
{
- return array_key_exists($key, $this->options) ? $this->options[$key] : null;
+ $options['http']['client'] = $options['http']['client'] ??
+ Psr18ClientDiscovery::find();
+ $options['http']['request_factory'] = $options['http']['request_factory'] ??
+ Psr17FactoryDiscovery::findRequestFactory();
+ $options['http']['response_factory'] = $options['http']['response_factory'] ??
+ Psr17FactoryDiscovery::findResponseFactory();
+ $options['http']['stream_factory'] = $options['http']['stream_factory'] ??
+ Psr17FactoryDiscovery::findStreamFactory();
+ $options['http']['uri_factory'] = $options['http']['uri_factory'] ??
+ Psr17FactoryDiscovery::findUriFactory();
+
+ // Automatically enable event listener acceptance if the end-user forgot to enable this.
+ if (
+ !empty($options['hydration']['only_for_specified_models']) &&
+ !$options['hydration']['event_listener_handles_hydration']
+ ) {
+ $options['hydration']['event_listener_handles_hydration'] = true;
+ }
+
+ $options['base_uri'] = sprintf(
+ '%s://%s',
+ $options['secure'] ? self::SCHEME_SECURE : self::SCHEME_INSECURE,
+ $options['host']
+ );
+
+ return $options;
}
/**
- * @param array $options
+ * Get the event dispatcher
*
- * @return array
+ * @return EventDispatcherInterface
*/
- public function setOptions(array $options = [])
+ public function getEventDispatcher(): EventDispatcherInterface
{
- $this->options = $this->configureOptions($options);
+ return $this->options['event_dispatcher']['adapter'];
}
/**
- * Construct the http client
- *
- * In case you are implementing your own adapter, the base url will be passed on through the options bag
- * at every call in the respective get / post methods etc. of the adapter.
- *
- * @return void
+ * @return HttpClient
*/
- protected function constructHttpClient()
+ public function getHttpClient(): HttpClient
{
- $hasHttpClient = (null !== $this->httpClient);
-
- $this->httpClient = new HttpClient($this->getOptions());
-
- if (!$hasHttpClient) {
- $this->httpClient->registerDefaults();
- }
+ return $this->httpClient;
}
/**
- * Reconstruct the HTTP Client
+ * @return array
*/
- protected function reconstructHttpClient()
+ public function getOptions()
{
- if (null !== $this->getHttpClient()) {
- $this->constructHttpClient();
- }
+ return $this->options;
}
/**
- * Configure options
- *
- * @param array $options
- * @return array
+ * @return GuestSessionToken|null
*/
- protected function configureOptions(array $options)
+ public function getGuestSessionToken(): ?GuestSessionToken
{
- $resolver = new OptionsResolver();
-
- $resolver->setDefaults([
- 'adapter' => null,
- 'secure' => true,
- 'host' => self::TMDB_URI,
- 'base_url' => null,
- 'token' => null,
- 'session_token' => null,
- 'event_dispatcher' => array_key_exists('event_dispatcher', $this->options) ? $this->options['event_dispatcher'] : new EventDispatcher(),
- 'cache' => [],
- 'log' => [],
- ]);
-
- $resolver->setRequired([
- 'adapter',
- 'host',
- 'token',
- 'secure',
- 'event_dispatcher',
- 'cache',
- 'log'
- ]);
-
- $resolver->setAllowedTypes('adapter', ['object', 'null']);
- $resolver->setAllowedTypes('host', ['string']);
- $resolver->setAllowedTypes('secure', ['bool']);
- $resolver->setAllowedTypes('token', ['object']);
- $resolver->setAllowedTypes('session_token', ['object', 'null']);
- $resolver->setAllowedTypes('event_dispatcher', ['object']);
-
- $this->options = $resolver->resolve($options);
-
- $this->postResolve($options);
-
- return $this->options;
+ return $this->options['guest_session_token'];
}
/**
- * Configure caching
- *
- * @param array $options
- * @return array
+ * @param GuestSessionToken|null $guestSessionToken
+ * @return self
*/
- protected function configureCacheOptions(array $options = [])
+ public function setGuestSessionToken(?GuestSessionToken $guestSessionToken): Client
{
- $resolver = new OptionsResolver();
-
- $resolver->setDefaults([
- 'enabled' => true,
- 'handler' => null,
- 'subscriber' => null,
- 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-tmdb-api',
- ]);
-
- $resolver->setRequired([
- 'enabled',
- 'handler',
- ]);
-
- $resolver->setAllowedTypes('enabled', ['bool']);
- $resolver->setAllowedTypes('handler', ['object', 'null']);
- $resolver->setAllowedTypes('subscriber', ['object', 'null']);
- $resolver->setAllowedTypes('path', ['string', 'null']);
+ $this->options['guest_session_token'] = $guestSessionToken;
- $options = $resolver->resolve(array_key_exists('cache', $options) ? $options['cache'] : []);
-
- if ($options['enabled'] && !$options['handler']) {
- $options['handler'] = new FilesystemCache($options['path']);
- }
-
- return $options;
+ return $this;
}
/**
- * Configure logging
- *
- * @param array $options
- * @return array
+ * @return ApiToken|BearerToken
*/
- protected function configureLogOptions(array $options = [])
+ public function getToken(): ApiToken
{
- $resolver = new OptionsResolver();
-
- $resolver->setDefaults([
- 'enabled' => false,
- 'level' => LogLevel::DEBUG,
- 'handler' => null,
- 'subscriber' => null,
- 'path' => sys_get_temp_dir() . DIRECTORY_SEPARATOR . 'php-tmdb-api.log',
- ]);
-
- $resolver->setRequired([
- 'enabled',
- 'level',
- 'handler',
- ]);
-
- $resolver->setAllowedTypes('enabled', ['bool']);
- $resolver->setAllowedTypes('level', ['string']);
- $resolver->setAllowedTypes('handler', ['object', 'null']);
- $resolver->setAllowedTypes('path', ['string', 'null']);
- $resolver->setAllowedTypes('subscriber', ['object', 'null']);
-
- $options = $resolver->resolve(array_key_exists('log', $options) ? $options['log'] : []);
-
- if ($options['enabled'] && !$options['handler']) {
- $options['handler'] = new StreamHandler(
- $options['path'],
- $options['level']
- );
- }
-
- return $options;
+ return $this->options['api_token'];
}
/**
- * Post resolve
+ * @param string $key
*
- * @param array $options
+ * @return array|mixed
*/
- protected function postResolve(array $options = [])
+ public function getOption(string $key)
{
- $this->options['base_url'] = sprintf(
- '%s://%s',
- $this->options['secure'] ? self::SCHEME_SECURE : self::SCHEME_INSECURE,
- $this->options['host']
- );
-
- if (!$this->options['adapter']) {
- $this->options['adapter'] = new GuzzleAdapter(
- new \GuzzleHttp\Client()
- );
- }
-
- $this->options['cache'] = $this->configureCacheOptions($options);
- $this->options['log'] = $this->configureLogOptions($options);
+ return array_key_exists($key, $this->options) ? $this->options[$key] : null;
}
}
diff --git a/lib/Tmdb/Common/ObjectHydrator.php b/lib/Tmdb/Common/ObjectHydrator.php
index 888f1b55..ff1c15f6 100644
--- a/lib/Tmdb/Common/ObjectHydrator.php
+++ b/lib/Tmdb/Common/ObjectHydrator.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Common;
use Tmdb\Exception\RuntimeException;
@@ -26,8 +28,8 @@ class ObjectHydrator
/**
* Hydrate the object with data
*
- * @param AbstractModel $object
- * @param array $data
+ * @param AbstractModel $object
+ * @param array $data
* @return AbstractModel
* @throws RuntimeException
*/
@@ -35,9 +37,7 @@ public function hydrate(AbstractModel $object, $data = [])
{
if (!empty($data)) {
foreach ($data as $k => $v) {
-
if (in_array($k, $object::$properties)) {
-
$method = $this->camelize(
sprintf('set_%s', $k)
);
@@ -63,7 +63,7 @@ public function hydrate(AbstractModel $object, $data = [])
*
* @see https://gist.github.com/troelskn/751517
*
- * @param string $candidate
+ * @param string $candidate
* @return string
*/
public function camelize($candidate)
diff --git a/lib/Tmdb/Common/ParameterBag.php b/lib/Tmdb/Common/ParameterBag.php
deleted file mode 100644
index 61b16f40..00000000
--- a/lib/Tmdb/Common/ParameterBag.php
+++ /dev/null
@@ -1,288 +0,0 @@
-
- * @author Benny ( borrowed array object extension )
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-
-namespace Tmdb\Common;
-
-class ParameterBag implements \IteratorAggregate, \Countable
-{
- /**
- * Parameter storage.
- *
- * @var array
- */
- protected $parameters;
- /**
- * Constructor.
- *
- * @param array $parameters An array of parameters
- *
- * @api
- */
- public function __construct(array $parameters = array())
- {
- $this->parameters = $parameters;
- }
- /**
- * Returns the parameters.
- *
- * @return array An array of parameters
- *
- * @api
- */
- public function all()
- {
- return $this->parameters;
- }
- /**
- * Returns the parameter keys.
- *
- * @return array An array of parameter keys
- *
- * @api
- */
- public function keys()
- {
- return array_keys($this->parameters);
- }
- /**
- * Replaces the current parameters by a new set.
- *
- * @param array $parameters An array of parameters
- *
- * @api
- */
- public function replace(array $parameters = array())
- {
- $this->parameters = $parameters;
- }
- /**
- * Adds parameters.
- *
- * @param array $parameters An array of parameters
- *
- * @api
- */
- public function add(array $parameters = array())
- {
- $this->parameters = array_replace($this->parameters, $parameters);
- }
- /**
- * Returns a parameter by name.
- *
- * @param string $path The key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return mixed
- *
- * @throws \InvalidArgumentException
- *
- * @api
- */
- public function get($path, $default = null, $deep = false)
- {
- if (!$deep || false === $pos = strpos($path, '[')) {
- return array_key_exists($path, $this->parameters) ? $this->parameters[$path] : $default;
- }
- $root = substr($path, 0, $pos);
- if (!array_key_exists($root, $this->parameters)) {
- return $default;
- }
- $value = $this->parameters[$root];
- $currentKey = null;
- for ($i = $pos, $c = strlen($path); $i < $c; $i++) {
- $char = $path[$i];
- if ('[' === $char) {
- if (null !== $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "[" at position %d.', $i));
- }
- $currentKey = '';
- } elseif (']' === $char) {
- if (null === $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "]" at position %d.', $i));
- }
- if (!is_array($value) || !array_key_exists($currentKey, $value)) {
- return $default;
- }
- $value = $value[$currentKey];
- $currentKey = null;
- } else {
- if (null === $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Unexpected "%s" at position %d.', $char, $i));
- }
- $currentKey .= $char;
- }
- }
- if (null !== $currentKey) {
- throw new \InvalidArgumentException(sprintf('Malformed path. Path must end with "]".'));
- }
-
- return $value;
- }
- /**
- * Sets a parameter by name.
- *
- * @param string $key The key
- * @param mixed $value The value
- *
- * @api
- */
- public function set($key, $value)
- {
- $this->parameters[$key] = $value;
- }
- /**
- * Returns true if the parameter is defined.
- *
- * @param string $key The key
- *
- * @return bool true if the parameter exists, false otherwise
- *
- * @api
- */
- public function has($key)
- {
- return array_key_exists($key, $this->parameters);
- }
- /**
- * Removes a parameter.
- *
- * @param string $key The key
- *
- * @api
- */
- public function remove($key)
- {
- unset($this->parameters[$key]);
- }
- /**
- * Returns the alphabetic characters of the parameter value.
- *
- * @param string $key The parameter key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return string The filtered value
- *
- * @api
- */
- public function getAlpha($key, $default = '', $deep = false)
- {
- return preg_replace('/[^[:alpha:]]/', '', $this->get($key, $default, $deep));
- }
- /**
- * Returns the alphabetic characters and digits of the parameter value.
- *
- * @param string $key The parameter key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return string The filtered value
- *
- * @api
- */
- public function getAlnum($key, $default = '', $deep = false)
- {
- return preg_replace('/[^[:alnum:]]/', '', $this->get($key, $default, $deep));
- }
- /**
- * Returns the digits of the parameter value.
- *
- * @param string $key The parameter key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return string The filtered value
- *
- * @api
- */
- public function getDigits($key, $default = '', $deep = false)
- {
- // we need to remove - and + because they're allowed in the filter
- return str_replace(array('-', '+'), '', $this->filter($key, $default, $deep, FILTER_SANITIZE_NUMBER_INT));
- }
- /**
- * Returns the parameter value converted to integer.
- *
- * @param string $key The parameter key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return int The filtered value
- *
- * @api
- */
- public function getInt($key, $default = 0, $deep = false)
- {
- return (int) $this->get($key, $default, $deep);
- }
- /**
- * Returns the parameter value converted to boolean.
- *
- * @param string $key The parameter key
- * @param mixed $default The default value if the parameter key does not exist
- * @param bool $deep If true, a path like foo[bar] will find deeper items
- *
- * @return bool The filtered value
- */
- public function getBoolean($key, $default = false, $deep = false)
- {
- return $this->filter($key, $default, $deep, FILTER_VALIDATE_BOOLEAN);
- }
- /**
- * Filter key.
- *
- * @param string $key Key.
- * @param mixed $default Default = null.
- * @param bool $deep Default = false.
- * @param int $filter FILTER_* constant.
- * @param mixed $options Filter options.
- *
- * @see http://php.net/manual/en/function.filter-var.php
- *
- * @return mixed
- */
- public function filter($key, $default = null, $deep = false, $filter = FILTER_DEFAULT, $options = array())
- {
- $value = $this->get($key, $default, $deep);
- // Always turn $options into an array - this allows filter_var option shortcuts.
- if (!is_array($options) && $options) {
- $options = array('flags' => $options);
- }
- // Add a convenience check for arrays.
- if (is_array($value) && !isset($options['flags'])) {
- $options['flags'] = FILTER_REQUIRE_ARRAY;
- }
-
- return filter_var($value, $filter, $options);
- }
- /**
- * Returns an iterator for parameters.
- *
- * @return \ArrayIterator An \ArrayIterator instance
- */
- public function getIterator()
- {
- return new \ArrayIterator($this->parameters);
- }
- /**
- * Returns the number of parameters.
- *
- * @return int The number of parameters
- */
- public function count()
- {
- return count($this->parameters);
- }
-}
diff --git a/lib/Tmdb/ConfigurationInterface.php b/lib/Tmdb/ConfigurationInterface.php
index 325e1ec3..8e0064b8 100644
--- a/lib/Tmdb/ConfigurationInterface.php
+++ b/lib/Tmdb/ConfigurationInterface.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb;
interface ConfigurationInterface
diff --git a/examples/search/api/list.php b/lib/Tmdb/Event/AfterHydrationEvent.php
similarity index 56%
rename from examples/search/api/list.php
rename to lib/Tmdb/Event/AfterHydrationEvent.php
index 4aeea774..f3ce021a 100644
--- a/examples/search/api/list.php
+++ b/lib/Tmdb/Event/AfterHydrationEvent.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+namespace Tmdb\Event;
-$result = $client->getSearchApi()->searchList('award');
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Symfony\Contracts\EventDispatcher\Event;
+use Tmdb\Model\AbstractModel;
-var_dump($result);
+class AfterHydrationEvent extends HydrationEvent
+{
+}
diff --git a/examples/movies/model/trailers.php b/lib/Tmdb/Event/BeforeHydrationEvent.php
similarity index 51%
rename from examples/movies/model/trailers.php
rename to lib/Tmdb/Event/BeforeHydrationEvent.php
index a1cc3f84..35f3594d 100644
--- a/examples/movies/model/trailers.php
+++ b/lib/Tmdb/Event/BeforeHydrationEvent.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
-require_once '../../../vendor/autoload.php';
-require_once '../../../apikey.php';
-$token = new \Tmdb\ApiToken(TMDB_API_KEY);
-$client = new \Tmdb\Client($token);
+namespace Tmdb\Event;
-$repository = new \Tmdb\Repository\MovieRepository($client);
-$collection = $repository->getTrailers(87421);
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Symfony\Contracts\EventDispatcher\Event;
+use Tmdb\Model\AbstractModel;
-var_dump($collection);
+class BeforeHydrationEvent extends HydrationEvent
+{
+}
diff --git a/lib/Tmdb/Event/BeforeRequestEvent.php b/lib/Tmdb/Event/BeforeRequestEvent.php
new file mode 100644
index 00000000..d66ba25e
--- /dev/null
+++ b/lib/Tmdb/Event/BeforeRequestEvent.php
@@ -0,0 +1,26 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Psr\EventDispatcher\StoppableEventInterface;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Symfony\Contracts\EventDispatcher\Event;
+use Tmdb\HttpClient\Request;
+
+class BeforeRequestEvent extends RequestEvent
+{
+}
diff --git a/lib/Tmdb/Event/HttpClientExceptionEvent.php b/lib/Tmdb/Event/HttpClientExceptionEvent.php
new file mode 100644
index 00000000..5a416689
--- /dev/null
+++ b/lib/Tmdb/Event/HttpClientExceptionEvent.php
@@ -0,0 +1,89 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+use Psr\Http\Client\ClientExceptionInterface;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+
+class HttpClientExceptionEvent extends StoppableEvent implements LoggableHttpEventInterface
+{
+ /**
+ * @var ClientExceptionInterface
+ */
+ private $exception;
+
+ /**
+ * @var RequestInterface
+ */
+ private $request;
+
+ /**
+ * @var ResponseInterface|null
+ */
+ private $response;
+
+ /**
+ * Constructor
+ *
+ * @param ClientExceptionInterface $exception
+ * @param RequestInterface $request
+ */
+ public function __construct(ClientExceptionInterface $exception, RequestInterface $request)
+ {
+ $this->exception = $exception;
+ $this->request = $request;
+ }
+
+ /**
+ * @return ClientExceptionInterface
+ */
+ public function getException(): ClientExceptionInterface
+ {
+ return $this->exception;
+ }
+
+ /**
+ * @return RequestInterface
+ */
+ public function getRequest(): RequestInterface
+ {
+ return $this->request;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasResponse(): bool
+ {
+ return null !== $this->response;
+ }
+
+ /**
+ * @return ResponseInterface|null
+ */
+ public function getResponse(): ?ResponseInterface
+ {
+ return $this->response;
+ }
+
+ /**
+ * @param ResponseInterface $response
+ */
+ public function setResponse(ResponseInterface $response): void
+ {
+ $this->response = $response;
+ }
+}
diff --git a/lib/Tmdb/Event/HydrationEvent.php b/lib/Tmdb/Event/HydrationEvent.php
index 994b58a1..15a3052b 100644
--- a/lib/Tmdb/Event/HydrationEvent.php
+++ b/lib/Tmdb/Event/HydrationEvent.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Event;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
use Symfony\Contracts\EventDispatcher\Event;
-use Tmdb\HttpClient\Request;
-use Tmdb\HttpClient\Response;
use Tmdb\Model\AbstractModel;
class HydrationEvent extends Event
@@ -30,12 +32,12 @@ class HydrationEvent extends Event
private $data;
/**
- * @var Request|null
+ * @var RequestInterface|null
*/
private $lastRequest;
/**
- * @var Response|null
+ * @var ResponseInterface|null
*/
private $lastResponse;
@@ -43,27 +45,27 @@ class HydrationEvent extends Event
* Constructor
*
* @param AbstractModel $subject
- * @param array $data
+ * @param array $data
*/
public function __construct(AbstractModel $subject, array $data = [])
{
$this->subject = $subject;
- $this->data = $data;
+ $this->data = $data;
}
/**
* @return AbstractModel
*/
- public function getSubject()
+ public function getSubject(): AbstractModel
{
return $this->subject;
}
/**
- * @param AbstractModel $subject
- * @return $this
+ * @param AbstractModel $subject
+ * @return self
*/
- public function setSubject($subject)
+ public function setSubject(AbstractModel $subject): HydrationEvent
{
$this->subject = $subject;
@@ -73,16 +75,16 @@ public function setSubject($subject)
/**
* @return array
*/
- public function getData()
+ public function getData(): array
{
return $this->data;
}
/**
- * @param array $data
- * @return $this
+ * @param array $data
+ * @return self
*/
- public function setData($data)
+ public function setData(array $data = []): HydrationEvent
{
$this->data = $data;
@@ -92,24 +94,24 @@ public function setData($data)
/**
* @return bool
*/
- public function hasData()
+ public function hasData(): bool
{
return !empty($this->data);
}
/**
- * @return Request
+ * @return RequestInterface|null
*/
- public function getLastRequest()
+ public function getLastRequest(): ?RequestInterface
{
return $this->lastRequest;
}
/**
- * @param Request|null $lastRequest
- * @return $this
+ * @param RequestInterface|null $lastRequest
+ * @return self
*/
- public function setLastRequest($lastRequest)
+ public function setLastRequest(?RequestInterface $lastRequest = null): HydrationEvent
{
$this->lastRequest = $lastRequest;
@@ -117,18 +119,18 @@ public function setLastRequest($lastRequest)
}
/**
- * @return Response
+ * @return ResponseInterface|null
*/
- public function getLastResponse()
+ public function getLastResponse(): ?ResponseInterface
{
return $this->lastResponse;
}
/**
- * @param Response|null $lastResponse
- * @return $this
+ * @param ResponseInterface|null $lastResponse
+ * @return self
*/
- public function setLastResponse($lastResponse)
+ public function setLastResponse(?ResponseInterface $lastResponse = null): HydrationEvent
{
$this->lastResponse = $lastResponse;
diff --git a/lib/Tmdb/Event/HydrationSubscriber.php b/lib/Tmdb/Event/HydrationSubscriber.php
deleted file mode 100644
index e7791e09..00000000
--- a/lib/Tmdb/Event/HydrationSubscriber.php
+++ /dev/null
@@ -1,76 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-namespace Tmdb\Event;
-
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Tmdb\Common\ObjectHydrator;
-use Tmdb\HttpClient\HttpClientEventSubscriber;
-
-/**
- * Class RequestSubscriber
- * @package Tmdb\Event
- */
-class HydrationSubscriber extends HttpClientEventSubscriber
-{
- /**
- * Get subscribed events
- *
- * @return array
- */
- public static function getSubscribedEvents()
- {
- return [
- TmdbEvents::HYDRATE => 'hydrate',
- ];
- }
-
- /**
- * Hydrate the subject with data
- *
- * @param HydrationEvent $event
- * @param string $eventName
- * @param EventDispatcherInterface $eventDispatcher
- *
- * @return \Tmdb\Model\AbstractModel
- */
- public function hydrate(HydrationEvent $event, $eventName, $eventDispatcher)
- {
- // Possibility to load serialized cache
- $eventDispatcher->dispatch( $event,TmdbEvents::BEFORE_HYDRATION);
-
- if ($event->isPropagationStopped()) {
- return $event->getSubject();
- }
-
- $subject = $this->hydrateSubject($event);
- $event->setSubject($subject);
-
- // Possibility to cache the data
- $eventDispatcher->dispatch( $event, TmdbEvents::AFTER_HYDRATION);
-
- return $event->getSubject();
- }
-
- /**
- * Hydrate the subject
- *
- * @param HydrationEvent $event
- * @return \Tmdb\Model\AbstractModel
- */
- public function hydrateSubject(HydrationEvent $event)
- {
- $objectHydrator = new ObjectHydrator();
-
- return $objectHydrator->hydrate($event->getSubject(), $event->getData());
- }
-}
diff --git a/lib/Tmdb/Event/Listener/HydrationListener.php b/lib/Tmdb/Event/Listener/HydrationListener.php
new file mode 100644
index 00000000..1d88eb1b
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/HydrationListener.php
@@ -0,0 +1,88 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener;
+
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Tmdb\Common\ObjectHydrator;
+use Tmdb\Event\AfterHydrationEvent;
+use Tmdb\Event\BeforeHydrationEvent;
+use Tmdb\Event\HydrationEvent;
+use Tmdb\Model\AbstractModel;
+
+/**
+ * Class RequestSubscriber
+ * @package Tmdb\Event
+ */
+class HydrationListener
+{
+ /**
+ * @var EventDispatcherInterface
+ */
+ private $eventDispatcher;
+
+ /**
+ * @var ObjectHydrator
+ */
+ private $hydrator;
+
+ /**
+ * HydrationListener constructor.
+ * @param EventDispatcherInterface $eventDispatcher
+ */
+ public function __construct(EventDispatcherInterface $eventDispatcher)
+ {
+ $this->eventDispatcher = $eventDispatcher;
+ $this->hydrator = new ObjectHydrator();
+ }
+
+ /**
+ * Hydrate the subject with data
+ *
+ * @param HydrationEvent $event
+ *
+ * @return AbstractModel
+ */
+ public function __invoke(HydrationEvent $event)
+ {
+ $before = new BeforeHydrationEvent($event->getSubject(), $event->getData());
+ $before->setLastRequest($event->getLastRequest());
+ $before->setLastResponse($event->getLastResponse());
+
+ $this->eventDispatcher->dispatch($before);
+
+ if ($before->isPropagationStopped()) {
+ return $before->getSubject();
+ }
+
+ $after = new AfterHydrationEvent($this->hydrateSubject($before), $before->getData());
+ $after->setLastRequest($event->getLastRequest());
+ $after->setLastResponse($event->getLastResponse());
+
+ $this->eventDispatcher->dispatch($after);
+
+ return $after->getSubject();
+ }
+
+ /**
+ * Hydrate the subject
+ *
+ * @param HydrationEvent $event
+ * @return AbstractModel
+ */
+ public function hydrateSubject(HydrationEvent $event)
+ {
+ return $this->hydrator->hydrate($event->getSubject(), $event->getData());
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php
new file mode 100644
index 00000000..431fe055
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Logger/LogApiErrorListener.php
@@ -0,0 +1,62 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Logger;
+
+use Psr\Log\LoggerInterface;
+use Tmdb\Event\TmdbExceptionEvent;
+use Tmdb\Formatter\TmdbApiException\SimpleTmdbApiExceptionFormatter;
+use Tmdb\Formatter\TmdbApiExceptionFormatterInterface;
+
+/**
+ * Class LogApiErrorListener
+ * @package Tmdb\Event
+ */
+class LogApiErrorListener
+{
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ /**
+ * @var TmdbApiExceptionFormatterInterface
+ */
+ private $formatter;
+
+ /**
+ * LogApiErrorListener constructor.
+ * @param LoggerInterface $logger
+ * @param TmdbApiExceptionFormatterInterface|null $formatter
+ */
+ public function __construct(LoggerInterface $logger, ?TmdbApiExceptionFormatterInterface $formatter = null)
+ {
+ $this->logger = $logger;
+ $this->formatter = $formatter ?: new SimpleTmdbApiExceptionFormatter();
+ }
+
+ /**
+ * @param TmdbExceptionEvent $event
+ * @return void
+ */
+ public function __invoke(TmdbExceptionEvent $event): void
+ {
+ $this->logger->critical(
+ sprintf(
+ 'Critical API exception:' . PHP_EOL . '%s',
+ $this->formatter->formatApiException($event->getException())
+ )
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php
new file mode 100644
index 00000000..16f1bfd3
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Logger/LogHttpMessageListener.php
@@ -0,0 +1,141 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Logger;
+
+use Psr\Http\Client\ClientExceptionInterface;
+use Psr\Log\LoggerInterface;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\HttpClientExceptionEvent;
+use Tmdb\Event\LoggableHttpEventInterface;
+use Tmdb\Event\ResponseEvent;
+use Tmdb\Formatter\HttpMessage\SimpleHttpMessageFormatter;
+use Tmdb\Formatter\HttpMessageFormatterInterface;
+
+/**
+ * Class LogHttpMessageListener
+ * @package Tmdb\Event
+ */
+class LogHttpMessageListener
+{
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ /**
+ * @var HttpMessageFormatterInterface
+ */
+ private $formatter;
+
+ /**
+ * LogHttpMessageListener constructor.
+ * @param LoggerInterface $logger
+ * @param HttpMessageFormatterInterface|null $formatter
+ */
+ public function __construct(LoggerInterface $logger, ?HttpMessageFormatterInterface $formatter = null)
+ {
+ $this->logger = $logger;
+ $this->formatter = $formatter ?: new SimpleHttpMessageFormatter();
+ }
+
+ /**
+ * @param LoggableHttpEventInterface $event
+ * @return void
+ */
+ public function __invoke(LoggableHttpEventInterface $event): void
+ {
+ if ($event instanceof BeforeRequestEvent) {
+ $this->logRequest($event);
+ }
+
+ if ($event instanceof ResponseEvent) {
+ $this->logResponse($event);
+ }
+
+ if ($event instanceof HttpClientExceptionEvent) {
+ $this->logClientException($event);
+ }
+ }
+
+ /**
+ * @param BeforeRequestEvent $event
+ */
+ protected function logRequest(BeforeRequestEvent $event): void
+ {
+ if (null !== $event->getRequest()->getBody()) {
+ $event->getRequest()->getBody()->rewind();
+ }
+
+ $context = [
+ 'length' => $event->getRequest()->getBody()->getSize(),
+ 'has_session_token' => $event->hasSessionToken()
+ ];
+
+ $this->logger->info(
+ sprintf(
+ 'Sending request:' . PHP_EOL . '%s',
+ $this->formatter->formatRequest($event->getRequest())
+ ),
+ $context
+ );
+ }
+
+ /**
+ * @param ResponseEvent $event
+ */
+ protected function logResponse(ResponseEvent $event): void
+ {
+ $cacheHit = $event->getResponse()->hasHeader('X-TMDB-Cache') &&
+ 'HIT' === $event->getResponse()->getHeaderLine('X-TMDB-Cache');
+
+ $context = [
+ 'status_code' => $event->getResponse()->getStatusCode(),
+ 'length' => $event->getResponse()->getBody()->getSize(),
+ 'cached' => $cacheHit
+ ];
+
+ $format = 'Received response:' . PHP_EOL . '%s';
+
+ if ($cacheHit) {
+ $format = 'Obtained cached response ' . PHP_EOL . '%s';
+ }
+
+ $this->logger->info(
+ sprintf(
+ $format,
+ $this->formatter->formatResponse($event->getResponse())
+ ),
+ $context
+ );
+ }
+
+ /**
+ * @param HttpClientExceptionEvent $event
+ */
+ protected function logClientException(HttpClientExceptionEvent $event): void
+ {
+ $context = [
+ 'request' => $event->getRequest()->getUri()->__toString()
+ ];
+
+ $this->logger->critical(
+ sprintf(
+ 'Critical http client error:' . PHP_EOL . '%s',
+ $this->formatter->formatClientException($event->getException())
+ ),
+ $context
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php
new file mode 100644
index 00000000..40ab81be
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Logger/LogHydrationListener.php
@@ -0,0 +1,78 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Logger;
+
+use Psr\Log\LoggerInterface;
+use Tmdb\Event\BeforeHydrationEvent;
+use Tmdb\Formatter\HttpMessageFormatterInterface;
+use Tmdb\Formatter\Hydration\SimpleHydrationFormatter;
+use Tmdb\Formatter\HydrationFormatterInterface;
+
+/**
+ * Class LogHydrationListener
+ * @package Tmdb\Event
+ */
+class LogHydrationListener
+{
+ /**
+ * @var LoggerInterface
+ */
+ private $logger;
+
+ /**
+ * @var HydrationFormatterInterface
+ */
+ private $formatter;
+
+ /**
+ * @var bool
+ */
+ private $withData;
+
+ /**
+ * RequestListener constructor.
+ * @param LoggerInterface $logger
+ * @param HydrationFormatterInterface|null $formatter
+ * @param bool $withData If true the context will contain the data used.
+ */
+ public function __construct(
+ LoggerInterface $logger,
+ ?HydrationFormatterInterface $formatter = null,
+ bool $withData = false
+ ) {
+ $this->logger = $logger;
+ $this->formatter = $formatter ?: new SimpleHydrationFormatter();
+ $this->withData = $withData;
+ }
+
+ /**
+ * @param BeforeHydrationEvent $event
+ * @return void
+ */
+ public function __invoke(BeforeHydrationEvent $event): void
+ {
+ $context = [];
+
+ if ($this->withData) {
+ $context['data'] = $event->getData();
+ $context['data_size'] = \mb_strlen(\GuzzleHttp\Utils::jsonEncode($event->getData()), 'UTF-8');
+ }
+
+ $this->logger->debug(
+ $this->formatter->formatBeforeEvent($event),
+ $context
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php b/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php
new file mode 100644
index 00000000..e69cbe57
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Psr6CachedRequestListener.php
@@ -0,0 +1,148 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener;
+
+use Http\Client\Common\Plugin\CachePlugin;
+use Http\Promise\FulfilledPromise;
+use Psr\Cache\CacheItemPoolInterface;
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Psr\Http\Client\ClientExceptionInterface;
+use Psr\Http\Message\StreamFactoryInterface;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\RequestEvent;
+use Tmdb\Event\ResponseEvent;
+use Tmdb\Exception\TmdbApiException;
+use Tmdb\HttpClient\HttpClient;
+
+/**
+ * As a shortcut for time being we make use of the php-http/cache-plugin.
+ *
+ * This is a little hacky, but I just wanna get 4.0 pushed ASAP. At a later stage we will review this again.
+ *
+ * Class Psr6CachedRequestListener
+ * @package Tmdb\Event\Listener
+ */
+class Psr6CachedRequestListener extends RequestListener
+{
+ /**
+ * @var CacheItemPoolInterface
+ */
+ private $cache;
+
+ /**
+ * @var StreamFactoryInterface
+ */
+ private $streamFactory;
+
+ /**
+ * @var array
+ */
+ private $options;
+
+ /**
+ * @var CachePlugin
+ */
+ private $httpCachePlugin;
+
+ /**
+ * Psr6CachedRequestListener constructor.
+ *
+ * @param HttpClient $httpClient
+ * @param EventDispatcherInterface $eventDispatcher
+ * @param CacheItemPoolInterface $cache
+ * @param StreamFactoryInterface $streamFactory
+ * @param array $options
+ * @param array $pluginOptions
+ */
+ public function __construct(
+ HttpClient $httpClient,
+ EventDispatcherInterface $eventDispatcher,
+ CacheItemPoolInterface $cache,
+ StreamFactoryInterface $streamFactory,
+ array $options = [],
+ array $pluginOptions = []
+ ) {
+ parent::__construct($httpClient, $eventDispatcher);
+
+ $this->cache = $cache;
+ $this->streamFactory = $streamFactory;
+ $this->options = $options;
+ $this->httpCachePlugin = CachePlugin::serverCache($this->cache, $this->streamFactory, $pluginOptions);
+ }
+
+ /**
+ * Add the API token to the headers.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ // Preparation of request parameters / Possibility to use for logging and caching etc.
+ $beforeRequestEvent = new BeforeRequestEvent($event->getRequest());
+ $this->eventDispatcher->dispatch($beforeRequestEvent);
+
+ $event->setRequest($beforeRequestEvent->getRequest());
+
+ if ($beforeRequestEvent->isPropagationStopped() && $beforeRequestEvent->hasResponse()) {
+ $event->setResponse($beforeRequestEvent->getResponse());
+ return;
+ }
+
+ $cachedResponse = true;
+
+ try {
+ $response = $this->httpCachePlugin->handleRequest(
+ $event->getRequest(),
+ function ($request) use ($beforeRequestEvent, &$cachedResponse) {
+ $cachedResponse = false;
+ $response = $this->sendRequest($beforeRequestEvent);
+
+ return new FulfilledPromise($response);
+ },
+ function () {
+ } // we do not need the plugin to go back
+ );
+
+ $response->then(
+ function ($result) use ($beforeRequestEvent) {
+ $beforeRequestEvent->setResponse($result);
+ }
+ );
+
+ $response = $beforeRequestEvent->getResponse();
+ } catch (ClientExceptionInterface $e) {
+ $response = $this->handleClientException($e, $beforeRequestEvent->getRequest());
+ }
+
+ try {
+ if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
+ throw $this->responseExceptionFactory->createTmdbApiException(
+ $beforeRequestEvent->getRequest(),
+ $response
+ );
+ }
+
+ $event->setRequest($beforeRequestEvent->getRequest());
+ $event->setResponse($response);
+ } catch (TmdbApiException $e) {
+ $response = $this->handleTmdbApiException($e);
+ }
+
+ $response = $response->withHeader('X-TMDB-Cache', $cachedResponse ? 'HIT' : 'MISS');
+
+ // Possibility to cache the request
+ $this->eventDispatcher->dispatch(new ResponseEvent($response, $event->getRequest()));
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php b/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php
new file mode 100644
index 00000000..bc317557
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/AcceptJsonRequestListener.php
@@ -0,0 +1,27 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Event\RequestEvent;
+
+class AcceptJsonRequestListener
+{
+ public function __invoke(RequestEvent $event): void
+ {
+ $event->setRequest(
+ $event->getRequest()->withHeader('Accept', 'application/json; charset=utf-8')
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php
new file mode 100644
index 00000000..5cedfa8a
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/AdultFilterRequestListener.php
@@ -0,0 +1,53 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Event\RequestEvent;
+use Tmdb\Helper\RequestQueryHelper;
+
+class AdultFilterRequestListener
+{
+ private $includeAdult;
+ /**
+ * @var RequestQueryHelper
+ */
+ private $requestQueryHelper;
+
+ /**
+ * AdultFilterRequestListener constructor.
+ * @param bool $includeAdult
+ */
+ public function __construct($includeAdult = false)
+ {
+ $this->includeAdult = $includeAdult;
+ $this->requestQueryHelper = new RequestQueryHelper();
+ }
+
+ /**
+ * Set the adult filter.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ $event->setRequest(
+ $this->requestQueryHelper->withQuery(
+ $event->getRequest(),
+ 'include_adult',
+ $this->includeAdult === true ? 'true' : 'false'
+ )
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php b/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php
new file mode 100644
index 00000000..2f4e2e33
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/ApiTokenRequestListener.php
@@ -0,0 +1,61 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Token\Api\ApiToken;
+use Tmdb\Token\Api\BearerToken;
+use Tmdb\Event\RequestEvent;
+use Tmdb\Helper\RequestQueryHelper;
+
+class ApiTokenRequestListener
+{
+ /**
+ * @var ApiToken
+ */
+ private $token;
+
+ /**
+ * @var RequestQueryHelper
+ */
+ private $requestQueryHelper;
+
+ /**
+ * ApiTokenRequestListener constructor.
+ * @param ApiToken $token
+ */
+ public function __construct(ApiToken $token)
+ {
+ $this->token = $token;
+ $this->requestQueryHelper = new RequestQueryHelper();
+ }
+
+ /**
+ * Add the API token to the headers.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ if ($this->token instanceof BearerToken) {
+ $event->setRequest(
+ $event->getRequest()->withHeader('Authorization', sprintf('Bearer %s', (string)$this->token))
+ );
+ } else {
+ $event->setRequest(
+ $this->requestQueryHelper->withQuery($event->getRequest(), 'api_key', (string)$this->token)
+ );
+ }
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php b/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php
new file mode 100644
index 00000000..95bf25a6
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/ContentTypeJsonRequestListener.php
@@ -0,0 +1,40 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Event\RequestEvent;
+
+class ContentTypeJsonRequestListener
+{
+ /**
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ $method = $event->getRequest()->getMethod();
+
+ if (
+ $method == 'POST' ||
+ $method == 'PUT' ||
+ $method == 'PATCH' ||
+ $method == 'DELETE'
+ ) {
+ $event->setRequest(
+ $event->getRequest()->withHeader('Content-Type', 'application/json')
+ );
+ }
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php
new file mode 100644
index 00000000..9c6d03c8
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/LanguageFilterRequestListener.php
@@ -0,0 +1,54 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Tmdb\Event\RequestEvent;
+use Tmdb\Helper\RequestQueryHelper;
+
+class LanguageFilterRequestListener
+{
+ /**
+ * @var string
+ */
+ private $language;
+
+ /**
+ * @var RequestQueryHelper
+ */
+ private $requestQueryHelper;
+
+ /**
+ * LanguageFilterRequestListener constructor.
+ * @param string $language
+ */
+ public function __construct($language = 'en')
+ {
+ $this->language = $language;
+ $this->requestQueryHelper = new RequestQueryHelper();
+ }
+
+ /**
+ * Set the language filter.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ $event->setRequest(
+ $this->requestQueryHelper->withQuery($event->getRequest(), 'language', $this->language)
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php b/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php
new file mode 100644
index 00000000..e7ef4bff
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/RegionFilterRequestListener.php
@@ -0,0 +1,54 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Symfony\Component\EventDispatcher\EventSubscriberInterface;
+use Tmdb\Event\RequestEvent;
+use Tmdb\Helper\RequestQueryHelper;
+
+class RegionFilterRequestListener
+{
+ /**
+ * @var string
+ */
+ private $region;
+
+ /**
+ * @var RequestQueryHelper
+ */
+ private $requestQueryHelper;
+
+ /**
+ * RegionFilterRequestListener constructor.
+ * @param string $region
+ */
+ public function __construct($region = 'en')
+ {
+ $this->region = $region;
+ $this->requestQueryHelper = new RequestQueryHelper();
+ }
+
+ /**
+ * Set the region filter.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ $event->setRequest(
+ $this->requestQueryHelper->withQuery($event->getRequest(), 'region', $this->region)
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php
new file mode 100644
index 00000000..cb550834
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/SessionTokenRequestListener.php
@@ -0,0 +1,68 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Event\RequestEvent;
+use Tmdb\Token\Session\GuestSessionToken;
+use Tmdb\Helper\RequestQueryHelper;
+use Tmdb\Token\Session\SessionBearerToken;
+use Tmdb\Token\Session\SessionToken;
+
+class SessionTokenRequestListener
+{
+ /**
+ * @var SessionToken
+ */
+ private $token;
+
+ /**
+ * @var RequestQueryHelper
+ */
+ private $requestQueryHelper;
+
+ /**
+ * SessionTokenRequestListener constructor.
+ * @param SessionToken $token
+ */
+ public function __construct(SessionToken $token)
+ {
+ $this->token = $token;
+ $this->requestQueryHelper = new RequestQueryHelper();
+ }
+
+ /**
+ * Set the token filter.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ if ($this->token instanceof SessionBearerToken) {
+ $event->setRequest(
+ $event->getRequest()->withHeader('Authorization', sprintf('Bearer %s', (string)$this->token))
+ );
+
+ return;
+ } elseif ($this->token instanceof GuestSessionToken) {
+ $key = 'guest_session_id';
+ } else {
+ $key = 'session_id';
+ }
+
+ $event->setRequest(
+ $this->requestQueryHelper->withQuery($event->getRequest(), $key, (string)$this->token)
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php
new file mode 100644
index 00000000..0190003d
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/Request/UserAgentRequestListener.php
@@ -0,0 +1,47 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener\Request;
+
+use Tmdb\Client;
+use Tmdb\Event\RequestEvent;
+
+class UserAgentRequestListener
+{
+ /**
+ * @var string|null
+ */
+ private $userAgent;
+
+ /**
+ * UserAgentRequestListener constructor.
+ * @param string|null $userAgent
+ */
+ public function __construct(?string $userAgent = null)
+ {
+ $this->userAgent = $userAgent ?? sprintf('php-tmdb/api/%s', Client::VERSION);
+ }
+
+ /**
+ * Add the API token to the headers.
+ *
+ * @param RequestEvent $event
+ */
+ public function __invoke(RequestEvent $event): void
+ {
+ $event->setRequest(
+ $event->getRequest()->withHeader('User-Agent', $this->userAgent)
+ );
+ }
+}
diff --git a/lib/Tmdb/Event/Listener/RequestListener.php b/lib/Tmdb/Event/Listener/RequestListener.php
new file mode 100644
index 00000000..359f346d
--- /dev/null
+++ b/lib/Tmdb/Event/Listener/RequestListener.php
@@ -0,0 +1,160 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event\Listener;
+
+use Exception;
+use Psr\EventDispatcher\EventDispatcherInterface;
+use Psr\Http\Client\ClientExceptionInterface;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Tmdb\Event\BeforeRequestEvent;
+use Tmdb\Event\HttpClientExceptionEvent;
+use Tmdb\Event\RequestEvent;
+use Tmdb\Event\ResponseEvent;
+use Tmdb\Event\TmdbExceptionEvent;
+use Tmdb\Exception\Factory\ResponseExceptionFactory;
+use Tmdb\Exception\TmdbApiException;
+use Tmdb\HttpClient\HttpClient;
+
+/**
+ * Class RequestSubscriber
+ * @package Tmdb\Event
+ */
+class RequestListener
+{
+ /**
+ * @var HttpClient
+ */
+ private $httpClient;
+
+ /**
+ * @var EventDispatcherInterface
+ */
+ protected $eventDispatcher;
+
+ /**
+ * @var ResponseExceptionFactory
+ */
+ protected $responseExceptionFactory;
+
+ /**
+ * RequestListener constructor.
+ * @param EventDispatcherInterface $eventDispatcher
+ */
+ public function __construct(HttpClient $httpClient, EventDispatcherInterface $eventDispatcher)
+ {
+ $this->httpClient = $httpClient;
+ $this->eventDispatcher = $eventDispatcher;
+ $this->responseExceptionFactory = new ResponseExceptionFactory();
+ }
+
+ /**
+ * @param RequestEvent $event
+ * @return void
+ * @throws Exception
+ * @throws TmdbApiException
+ * @throws ClientExceptionInterface
+ */
+ public function __invoke(RequestEvent $event)
+ {
+ // Preparation of request parameters / Possibility to use for logging and caching etc.
+ $beforeRequestEvent = new BeforeRequestEvent($event->getRequest());
+ $this->eventDispatcher->dispatch($beforeRequestEvent);
+
+ $event->setRequest($beforeRequestEvent->getRequest());
+
+ if ($beforeRequestEvent->isPropagationStopped() && $beforeRequestEvent->hasResponse()) {
+ $event->setResponse($beforeRequestEvent->getResponse());
+ return;
+ }
+
+ try {
+ $response = $this->sendRequest($beforeRequestEvent);
+ } catch (ClientExceptionInterface $e) {
+ $response = $this->handleClientException($e, $beforeRequestEvent->getRequest());
+ }
+
+ try {
+ if ($response->getStatusCode() >= 400 && $response->getStatusCode() < 600) {
+ throw $this->responseExceptionFactory->createTmdbApiException(
+ $beforeRequestEvent->getRequest(),
+ $response
+ );
+ }
+
+ $event->setRequest($beforeRequestEvent->getRequest());
+ $event->setResponse($response);
+ } catch (TmdbApiException $e) {
+ $response = $this->handleTmdbApiException($e);
+ }
+
+ // Possibility to cache the request
+ $this->eventDispatcher->dispatch(new ResponseEvent($response, $event->getRequest()));
+ }
+
+ /**
+ * Call upon the adapter to create an response object
+ *
+ * @param RequestEvent $event
+ * @return ResponseInterface
+ * @throws Exception
+ * @throws ClientExceptionInterface
+ */
+ public function sendRequest(RequestEvent $event): ResponseInterface
+ {
+ return $this->httpClient->getPsr18Client()->sendRequest($event->getRequest());
+ }
+
+ /**
+ * @param ClientExceptionInterface $e
+ * @param RequestInterface $request
+ * @return ResponseInterface
+ * @throws ClientExceptionInterface
+ */
+ protected function handleClientException(
+ ClientExceptionInterface $e,
+ RequestInterface $request
+ ): ResponseInterface {
+ // In the event of failures, you can recover certain exceptions.
+ $exceptionEvent = new HttpClientExceptionEvent($e, $request);
+
+ $this->eventDispatcher->dispatch($exceptionEvent);
+
+ if (!$exceptionEvent->isPropagationStopped() || !$exceptionEvent->hasResponse()) {
+ throw $e;
+ }
+
+ return $exceptionEvent->getResponse();
+ }
+
+ /**
+ * @param TmdbApiException $e
+ * @return ResponseInterface
+ * @throws TmdbApiException
+ */
+ protected function handleTmdbApiException(TmdbApiException $e): ResponseInterface
+ {
+ // In the event of failures, you can recover certain exceptions.
+ $exceptionEvent = new TmdbExceptionEvent($e);
+
+ $this->eventDispatcher->dispatch($exceptionEvent);
+
+ if (!$exceptionEvent->isPropagationStopped() || !$exceptionEvent->hasResponse()) {
+ throw $e;
+ }
+
+ return $exceptionEvent->getResponse();
+ }
+}
diff --git a/lib/Tmdb/Event/LoggableHttpEventInterface.php b/lib/Tmdb/Event/LoggableHttpEventInterface.php
new file mode 100644
index 00000000..6cbf63f8
--- /dev/null
+++ b/lib/Tmdb/Event/LoggableHttpEventInterface.php
@@ -0,0 +1,19 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+interface LoggableHttpEventInterface
+{
+}
diff --git a/lib/Tmdb/Event/RequestEvent.php b/lib/Tmdb/Event/RequestEvent.php
index 3882a047..e8997afd 100644
--- a/lib/Tmdb/Event/RequestEvent.php
+++ b/lib/Tmdb/Event/RequestEvent.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Event;
-use Symfony\Contracts\EventDispatcher\Event;
-use Tmdb\Common\ParameterBag;
-use Tmdb\HttpClient\Request;
-use Tmdb\HttpClient\Response;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Tmdb\Token\Session\SessionToken;
-class RequestEvent extends Event
+/**
+ * Class RequestEvent
+ * @package Tmdb\Event
+ */
+class RequestEvent extends StoppableEvent implements LoggableHttpEventInterface
{
/**
- * @var Request
+ * @var RequestInterface
*/
private $request;
/**
- * @var Response
+ * @var ?ResponseInterface
*/
private $response;
+ /**
+ * @var ?SessionToken
+ */
+ private $sessionToken;
+
/**
* Construct the request event
*
- * @param Request $request
+ * @param RequestInterface $request
+ * @param SessionToken|null $sessionToken
*/
- public function __construct(Request $request)
+ public function __construct(RequestInterface $request, ?SessionToken $sessionToken = null)
{
$this->request = $request;
+ $this->sessionToken = $sessionToken;
}
/**
- * @return ParameterBag
+ * @return RequestInterface
*/
- public function getParameters()
+ public function getRequest(): RequestInterface
{
- return $this->request->getParameters();
+ return $this->request;
}
/**
- * @return string
+ * @param RequestInterface $request
+ * @return self
*/
- public function getPath()
+ public function setRequest(RequestInterface $request): RequestEvent
{
- return $this->request->getPath();
- }
+ $this->request = $request;
- /**
- * @return string
- */
- public function getMethod()
- {
- return $this->request->getMethod();
+ return $this;
}
/**
- * @return ParameterBag
+ * @return ?ResponseInterface
*/
- public function getHeaders()
+ public function getResponse(): ?ResponseInterface
{
- return $this->request->getHeaders();
+ return $this->response;
}
/**
- * @return null
+ * @param ResponseInterface $response
+ * @return self
*/
- public function getBody()
+ public function setResponse(ResponseInterface $response): RequestEvent
{
- return $this->request->getBody();
- }
+ $this->response = $response;
- /**
- * @return Request
- */
- public function getRequest()
- {
- return $this->request;
+ return $this;
}
/**
- * @param Request $request
- * @return $this
+ * @return bool
*/
- public function setRequest($request)
+ public function hasResponse()
{
- $this->request = $request;
-
- return $this;
+ return $this->response instanceof ResponseInterface;
}
/**
- * @return string
+ * @return ?SessionToken
*/
- public function getResponse()
+ public function getSessionToken(): ?SessionToken
{
- return $this->response;
+ return $this->sessionToken;
}
/**
- * @param Response $response
- * @return $this
+ * @param SessionToken|null $sessionToken
+ * @return self
*/
- public function setResponse($response)
+ public function setSessionToken(?SessionToken $sessionToken = null): RequestEvent
{
- $this->response = $response;
+ $this->sessionToken = $sessionToken;
return $this;
}
@@ -120,8 +119,8 @@ public function setResponse($response)
/**
* @return bool
*/
- public function hasResponse()
+ public function hasSessionToken(): bool
{
- return null !== $this->response;
+ return $this->sessionToken instanceof SessionToken;
}
}
diff --git a/lib/Tmdb/Event/RequestSubscriber.php b/lib/Tmdb/Event/RequestSubscriber.php
deleted file mode 100644
index 6b1b782f..00000000
--- a/lib/Tmdb/Event/RequestSubscriber.php
+++ /dev/null
@@ -1,92 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-namespace Tmdb\Event;
-
-use Symfony\Component\EventDispatcher\EventDispatcherInterface;
-use Tmdb\Exception\RuntimeException;
-use Tmdb\HttpClient\HttpClientEventSubscriber;
-use Tmdb\HttpClient\Response;
-
-/**
- * Class RequestSubscriber
- * @package Tmdb\Event
- */
-class RequestSubscriber extends HttpClientEventSubscriber
-{
- public static function getSubscribedEvents()
- {
- return [
- TmdbEvents::REQUEST => 'send',
- ];
- }
-
- /**
- * @param RequestEvent $event
- * @param string $eventName
- * @param EventDispatcherInterface $eventDispatcher
- *
- * @return string|Response
- */
- public function send(RequestEvent $event, $eventName, EventDispatcherInterface $eventDispatcher)
- {
- // Preparation of request parameters / Possibility to use for logging and caching etc.
- $eventDispatcher->dispatch($event,TmdbEvents::BEFORE_REQUEST);
-
- if ($event->isPropagationStopped() && $event->hasResponse()) {
- return $event->getResponse();
- }
-
- $response = $this->sendRequest($event);
- $event->setResponse($response);
-
- // Possibility to cache the request
- $eventDispatcher->dispatch($event, TmdbEvents::AFTER_REQUEST);
-
- return $response;
- }
-
- /**
- * Call upon the adapter to create an response object
- *
- * @param RequestEvent $event
- * @throws \Exception
- * @return Response
- */
- public function sendRequest(RequestEvent $event)
- {
- switch ($event->getMethod()) {
- case 'GET':
- $response = $this->getHttpClient()->getAdapter()->get($event->getRequest());
- break;
- case 'HEAD':
- $response = $this->getHttpClient()->getAdapter()->head($event->getRequest());
- break;
- case 'POST':
- $response = $this->getHttpClient()->getAdapter()->post($event->getRequest());
- break;
- case 'PUT':
- $response = $this->getHttpClient()->getAdapter()->put($event->getRequest());
- break;
- case 'PATCH':
- $response = $this->getHttpClient()->getAdapter()->patch($event->getRequest());
- break;
- case 'DELETE':
- $response = $this->getHttpClient()->getAdapter()->delete($event->getRequest());
- break;
- default:
- throw new RuntimeException(sprintf('Unknown request method "%s".', $event->getMethod()));
- }
-
- return $response;
- }
-}
diff --git a/lib/Tmdb/Event/ResponseEvent.php b/lib/Tmdb/Event/ResponseEvent.php
new file mode 100644
index 00000000..e928a962
--- /dev/null
+++ b/lib/Tmdb/Event/ResponseEvent.php
@@ -0,0 +1,98 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Symfony\Contracts\EventDispatcher\Event;
+
+class ResponseEvent implements LoggableHttpEventInterface
+{
+ /**
+ * @var RequestInterface
+ */
+ private $request;
+
+ /**
+ * @var ResponseInterface
+ */
+ private $response;
+
+ /**
+ * Construct the request event
+ *
+ * @param ResponseInterface $response
+ * @param RequestInterface $request
+ */
+ public function __construct(ResponseInterface $response, RequestInterface $request)
+ {
+ $this->response = $response;
+ $this->request = $request;
+ }
+
+ /**
+ * @return RequestInterface
+ */
+ public function getRequest(): RequestInterface
+ {
+ return $this->request;
+ }
+
+ /**
+ * @param RequestInterface $request
+ * @return self
+ */
+ public function setRequest($request)
+ {
+ $this->request = $request;
+
+ return $this;
+ }
+
+ /**
+ * @return ResponseInterface
+ */
+ public function getResponse(): ResponseInterface
+ {
+ return $this->response;
+ }
+
+ /**
+ * @param ResponseInterface $response
+ * @return self
+ */
+ public function setResponse(ResponseInterface $response)
+ {
+ $this->response = $response;
+
+ return $this;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasResponse()
+ {
+ return null !== $this->response;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasRequest()
+ {
+ return null !== $this->request;
+ }
+}
diff --git a/lib/Tmdb/Event/StoppableEvent.php b/lib/Tmdb/Event/StoppableEvent.php
new file mode 100644
index 00000000..91dedb0e
--- /dev/null
+++ b/lib/Tmdb/Event/StoppableEvent.php
@@ -0,0 +1,32 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+use Psr\EventDispatcher\StoppableEventInterface;
+
+class StoppableEvent implements StoppableEventInterface
+{
+ protected $isPropagationStopped;
+
+ public function stopPropagation(): void
+ {
+ $this->isPropagationStopped = true;
+ }
+
+ public function isPropagationStopped(): bool
+ {
+ return (bool)$this->isPropagationStopped;
+ }
+}
diff --git a/lib/Tmdb/Event/TmdbEvents.php b/lib/Tmdb/Event/TmdbEvents.php
deleted file mode 100644
index 34426cc9..00000000
--- a/lib/Tmdb/Event/TmdbEvents.php
+++ /dev/null
@@ -1,26 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-namespace Tmdb\Event;
-
-final class TmdbEvents
-{
- /** Request */
- const BEFORE_REQUEST = 'tmdb.before_request';
- const REQUEST = 'tmdb.request';
- const AFTER_REQUEST = 'tmdb.after_request';
-
- /** Hydration */
- const BEFORE_HYDRATION = 'tmdb.before_hydration';
- const HYDRATE = 'tmdb.hydrate';
- const AFTER_HYDRATION = 'tmdb.after_hydration';
-}
diff --git a/lib/Tmdb/Event/TmdbExceptionEvent.php b/lib/Tmdb/Event/TmdbExceptionEvent.php
new file mode 100644
index 00000000..2bdde6dc
--- /dev/null
+++ b/lib/Tmdb/Event/TmdbExceptionEvent.php
@@ -0,0 +1,73 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Event;
+
+use Psr\Http\Message\ResponseInterface;
+use Tmdb\Exception\TmdbApiException;
+
+class TmdbExceptionEvent extends StoppableEvent
+{
+ /**
+ * @var TmdbApiException
+ */
+ private $exception;
+
+ /**
+ * @var ResponseInterface
+ */
+ private $response;
+
+ /**
+ * Constructor
+ *
+ * @param TmdbApiException $exception
+ */
+ public function __construct(TmdbApiException $exception)
+ {
+ $this->exception = $exception;
+ }
+
+ /**
+ * @return TmdbApiException
+ */
+ public function getException(): TmdbApiException
+ {
+ return $this->exception;
+ }
+
+ /**
+ * @return bool
+ */
+ public function hasResponse(): bool
+ {
+ return null !== $this->response;
+ }
+
+ /**
+ * @return ResponseInterface|null
+ */
+ public function getResponse(): ?ResponseInterface
+ {
+ return $this->response;
+ }
+
+ /**
+ * @param ResponseInterface $response
+ */
+ public function setResponse(ResponseInterface $response): void
+ {
+ $this->response = $response;
+ }
+}
diff --git a/lib/Tmdb/Exception/ApiTokenMissingException.php b/lib/Tmdb/Exception/ApiTokenMissingException.php
index 0151f2dd..ca00c9e8 100644
--- a/lib/Tmdb/Exception/ApiTokenMissingException.php
+++ b/lib/Tmdb/Exception/ApiTokenMissingException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php b/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php
new file mode 100644
index 00000000..7f6e7d60
--- /dev/null
+++ b/lib/Tmdb/Exception/Factory/ResponseExceptionFactory.php
@@ -0,0 +1,59 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Exception\Factory;
+
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
+use Tmdb\Exception\RuntimeException;
+use Tmdb\Exception\TmdbApiException;
+use Tmdb\Exception\UnexpectedResponseException;
+
+class ResponseExceptionFactory
+{
+ /**
+ * @param RequestInterface $request
+ * @param ResponseInterface $response
+ * @return TmdbApiException
+ * @throws UnexpectedResponseException
+ * @throws RuntimeException
+ */
+ public function createTmdbApiException(RequestInterface $request, ResponseInterface $response): TmdbApiException
+ {
+ try {
+ if (
+ $response->hasHeader('content-type') &&
+ strpos($response->getHeaderLine('content-type'), 'application/json') !== false
+ ) {
+ $response->getBody()->rewind();
+
+ $body = $response->getBody()->getContents();
+ $data = json_decode($body, false, 512, JSON_THROW_ON_ERROR);
+
+ return new TmdbApiException(
+ $data->status_code,
+ $data->status_message,
+ $request,
+ $response
+ );
+ }
+ } catch (\Exception $e) {
+ throw new RuntimeException('Unable to create TmdbApiException, could not decode response body.');
+ }
+
+ throw new UnexpectedResponseException(
+ 'Unable to create an helpful Exception, server did not contain a json body.'
+ );
+ }
+}
diff --git a/lib/Tmdb/Exception/InvalidArgumentException.php b/lib/Tmdb/Exception/InvalidArgumentException.php
index a9ab221f..b49a6cec 100644
--- a/lib/Tmdb/Exception/InvalidArgumentException.php
+++ b/lib/Tmdb/Exception/InvalidArgumentException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/JsonDecodingException.php b/lib/Tmdb/Exception/JsonDecodingException.php
new file mode 100644
index 00000000..0b837f1a
--- /dev/null
+++ b/lib/Tmdb/Exception/JsonDecodingException.php
@@ -0,0 +1,19 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Exception;
+
+class JsonDecodingException extends UnexpectedResponseException
+{
+}
diff --git a/lib/Tmdb/Exception/MissingArgumentException.php b/lib/Tmdb/Exception/MissingArgumentException.php
index f2941f92..51f90f20 100644
--- a/lib/Tmdb/Exception/MissingArgumentException.php
+++ b/lib/Tmdb/Exception/MissingArgumentException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/MissingSessionTokenException.php b/lib/Tmdb/Exception/MissingSessionTokenException.php
index 79c0a3db..2b71b12d 100644
--- a/lib/Tmdb/Exception/MissingSessionTokenException.php
+++ b/lib/Tmdb/Exception/MissingSessionTokenException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/NotImplementedException.php b/lib/Tmdb/Exception/NotImplementedException.php
index 5d26f11a..777944c1 100644
--- a/lib/Tmdb/Exception/NotImplementedException.php
+++ b/lib/Tmdb/Exception/NotImplementedException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
+use Exception;
+
/**
* Class NotImplementedException
* @package Tmdb\Exception
*/
-class NotImplementedException extends \Exception
+class NotImplementedException extends Exception
{
}
diff --git a/lib/Tmdb/Exception/NullResponseException.php b/lib/Tmdb/Exception/NullResponseException.php
deleted file mode 100644
index 3d9381d2..00000000
--- a/lib/Tmdb/Exception/NullResponseException.php
+++ /dev/null
@@ -1,73 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-namespace Tmdb\Exception;
-use Tmdb\HttpClient\Request;
-
-/**
- * Class RuntimeException
- * @package Tmdb\Exception
- */
-class NullResponseException extends RuntimeException
-{
- /**
- * @var Request
- */
- protected $request;
-
- /**
- * @param Request $request
- * @param \Exception|null $previous
- */
- public function __construct(Request $request, \Exception $previous = null)
- {
- $this->request = $request;
-
- if (null !== $previous && is_a($previous, 'GuzzleHttp\Exception\RequestException')) {
- $message = sprintf(
- 'The request to path "%s" with query parameters "%s" failed to return a valid response. The previous exception reported "%s" at "%s:%d".',
- $request->getPath(),
- json_encode($request->getParameters()->all()),
- $previous->getMessage(),
- $previous->getFile(),
- $previous->getLine()
- );
- } else {
- $message = sprintf(
- 'The request to path "%s" with query parameters "%s" failed to return a valid response.',
- $request->getPath(),
- json_encode($request->getParameters()->all())
- );
- }
-
- parent::__construct($message, 0, $previous);
- }
-
- /**
- * @return Request
- */
- public function getRequest()
- {
- return $this->request;
- }
-
- /**
- * @param Request $request
- * @return $this
- */
- public function setRequest(Request $request)
- {
- $this->request = $request;
-
- return $this;
- }
-}
diff --git a/lib/Tmdb/Exception/RuntimeException.php b/lib/Tmdb/Exception/RuntimeException.php
index f7d8537e..67121dd9 100644
--- a/lib/Tmdb/Exception/RuntimeException.php
+++ b/lib/Tmdb/Exception/RuntimeException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/TmdbApiException.php b/lib/Tmdb/Exception/TmdbApiException.php
index fa00fab7..402eb530 100644
--- a/lib/Tmdb/Exception/TmdbApiException.php
+++ b/lib/Tmdb/Exception/TmdbApiException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
-use Tmdb\HttpClient\Request;
-use Tmdb\HttpClient\Response;
+
+use Exception;
+use Psr\Http\Message\RequestInterface;
+use Psr\Http\Message\ResponseInterface;
/**
* Class TmdbApiException
* @package Tmdb\Exception
*/
-class TmdbApiException extends \Exception
+class TmdbApiException extends Exception
{
- const STATUS_SUCCESS = 1;
- const STATUS_INVALID_SERVICE = 2;
- const STATUS_AUTHENTICATION_FAILED_NO_PERMISSION = 3;
- const STATUS_INVALID_FORMAT = 4;
- const STATUS_INVALID_PARAMETERS = 5;
- const STATUS_INVALID_ID = 6;
- const STATUS_INVALID_API_KEY = 7;
- const STATUS_DUPLICATE_ENTRY = 8;
- const STATUS_SERVICE_OFFLINE = 9;
- const STATUS_SUSPENDED_API_KEY = 10;
- const STATUS_INTERNAL_ERROR = 11;
- const STATUS_UPDATE_SUCCESS = 12;
- const STATUS_DELETE_SUCCESS = 13;
- const STATUS_AUTHENTICATION_FAILED = 14;
- const STATUS_FAILED = 15;
- const STATUS_DEVICE_DENIED = 16;
- const STATUS_SESSION_DENIED = 17;
- const STATUS_VALIDATION_FAILED = 18;
- const STATUS_INVALID_ACCEPT_HEADER = 19;
- const STATUS_INVALID_DATE_RANGE = 20;
- const STATUS_ENTRY_NOT_FOUND = 21;
- const STATUS_INVALID_PAGE = 22;
- const STATUS_INVALID_DATE = 23;
- const STATUS_BACKEND_TIMEOUT = 24;
- const STATUS_REQUEST_COUNT = 25;
- const STATUS_USERNAME_PASSWORD_NOT_PROVIDED = 26;
- const STATUS_TOO_MANY_APPEND_TO_RESPONSE = 27;
- const STATUS_INVALID_TIMEZONE = 28;
- const STATUS_CONFIRM_REQUIRED = 29;
- const STATUS_INVALID_USERNAME_PASSWORD = 30;
- const STATUS_ACCOUNT_DISABLED = 31;
- const STATUS_EMAIL_NOT_VERIFIED = 32;
- const STATUS_INVALID_REQUEST_TOKEN = 33;
- const STATUS_RESOURCE_NOT_FOUND = 34;
+ public const STATUS_SUCCESS = 1;
+ public const STATUS_INVALID_SERVICE = 2;
+ public const STATUS_AUTHENTICATION_FAILED_NO_PERMISSION = 3;
+ public const STATUS_INVALID_FORMAT = 4;
+ public const STATUS_INVALID_PARAMETERS = 5;
+ public const STATUS_INVALID_ID = 6;
+ public const STATUS_INVALID_API_KEY = 7;
+ public const STATUS_DUPLICATE_ENTRY = 8;
+ public const STATUS_SERVICE_OFFLINE = 9;
+ public const STATUS_SUSPENDED_API_KEY = 10;
+ public const STATUS_INTERNAL_ERROR = 11;
+ public const STATUS_UPDATE_SUCCESS = 12;
+ public const STATUS_DELETE_SUCCESS = 13;
+ public const STATUS_AUTHENTICATION_FAILED = 14;
+ public const STATUS_FAILED = 15;
+ public const STATUS_DEVICE_DENIED = 16;
+ public const STATUS_SESSION_DENIED = 17;
+ public const STATUS_VALIDATION_FAILED = 18;
+ public const STATUS_INVALID_ACCEPT_HEADER = 19;
+ public const STATUS_INVALID_DATE_RANGE = 20;
+ public const STATUS_ENTRY_NOT_FOUND = 21;
+ public const STATUS_INVALID_PAGE = 22;
+ public const STATUS_INVALID_DATE = 23;
+ public const STATUS_BACKEND_TIMEOUT = 24;
+ public const STATUS_REQUEST_COUNT = 25;
+ public const STATUS_USERNAME_PASSWORD_NOT_PROVIDED = 26;
+ public const STATUS_TOO_MANY_APPEND_TO_RESPONSE = 27;
+ public const STATUS_INVALID_TIMEZONE = 28;
+ public const STATUS_CONFIRM_REQUIRED = 29;
+ public const STATUS_INVALID_USERNAME_PASSWORD = 30;
+ public const STATUS_ACCOUNT_DISABLED = 31;
+ public const STATUS_EMAIL_NOT_VERIFIED = 32;
+ public const STATUS_INVALID_REQUEST_TOKEN = 33;
+ public const STATUS_RESOURCE_NOT_FOUND = 34;
/**
- * @var Request
+ * @var RequestInterface
*/
protected $request;
/**
- * @var Response
+ * @var ResponseInterface
*/
protected $response;
/**
* Create the exception
*
- * @param int $code
- * @param string $message
- * @param Request|null $request
- * @param Response|null $response
- * @param \Exception|null $previous
+ * @param int $code
+ * @param string $message
+ * @param RequestInterface|null $request
+ * @param ResponseInterface|null $response
+ * @param Exception|null $previous
*/
- public function __construct($code, $message, $request = null, $response = null, \Exception $previous = null)
- {
+ public function __construct(
+ int $code,
+ string $message,
+ ?RequestInterface $request = null,
+ ?ResponseInterface $response = null,
+ ?Exception $previous = null
+ ) {
parent::__construct($message, $code, $previous);
- $this->request = $request;
+ $this->request = $request;
$this->response = $response;
}
/**
- * @return Request
+ * @return RequestInterface
*/
public function getRequest()
{
@@ -91,10 +100,10 @@ public function getRequest()
}
/**
- * @param Request $request
- * @return $this
+ * @param RequestInterface $request
+ * @return self
*/
- public function setRequest($request)
+ public function setRequest(RequestInterface $request): TmdbApiException
{
$this->request = $request;
@@ -102,7 +111,7 @@ public function setRequest($request)
}
/**
- * @return Response
+ * @return ResponseInterface
*/
public function getResponse()
{
@@ -110,10 +119,10 @@ public function getResponse()
}
/**
- * @param Response $response
- * @return $this
+ * @param ResponseInterface $response
+ * @return self
*/
- public function setResponse($response)
+ public function setResponse(ResponseInterface $response): TmdbApiException
{
$this->response = $response;
diff --git a/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php
index 99e33442..2d98d095 100644
--- a/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php
+++ b/lib/Tmdb/Exception/UnauthorizedRequestTokenException.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Exception;
/**
diff --git a/lib/Tmdb/Exception/UnexpectedResponseException.php b/lib/Tmdb/Exception/UnexpectedResponseException.php
new file mode 100644
index 00000000..77e39354
--- /dev/null
+++ b/lib/Tmdb/Exception/UnexpectedResponseException.php
@@ -0,0 +1,21 @@
+
+ * @copyright (c) 2013, Michael Roterman
+ * @version 4.0.0
+ */
+
+namespace Tmdb\Exception;
+
+use Psr\Http\Client\ClientExceptionInterface;
+
+class UnexpectedResponseException extends RuntimeException implements ClientExceptionInterface
+{
+}
diff --git a/lib/Tmdb/Factory/AbstractFactory.php b/lib/Tmdb/Factory/AbstractFactory.php
index 4ed0ba2c..74eeafe1 100644
--- a/lib/Tmdb/Factory/AbstractFactory.php
+++ b/lib/Tmdb/Factory/AbstractFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
+use RuntimeException;
+use Tmdb\Common\ObjectHydrator;
+use Tmdb\Event\BeforeHydrationEvent;
use Tmdb\Event\HydrationEvent;
use Tmdb\Event\TmdbEvents;
use Tmdb\HttpClient\HttpClient;
@@ -24,6 +29,9 @@
/**
* Class AbstractFactory
+ *
+ * @template T of AbstractModel
+ *
* @package Tmdb\Factory
*/
abstract class AbstractFactory
@@ -46,64 +54,29 @@ public function __construct(HttpClient $httpClient)
/**
* Convert an array to an hydrated object
*
- * @param array $data
- * @return AbstractModel
+ * @param array $data
+ * @return T
*/
abstract public function create(array $data = []);
/**
* Convert an array with an collection of items to an hydrated object collection
*
- * @param array $data
- * @return GenericCollection
+ * @param array $data
+ * @return GenericCollection
*/
abstract public function createCollection(array $data = []);
- /**
- * Get the http client
- *
- * @return HttpClient
- */
- protected function getHttpClient()
- {
- return $this->httpClient;
- }
-
- /**
- * Create a generic collection of data and map it on the class by it's static parameter $properties
- *
- * @param array $data
- * @param $class
- * @return GenericCollection
- */
- protected function createGenericCollection($data = [], $class)
- {
- if (is_object($class)) {
- $class = get_class($class);
- }
-
- $collection = new GenericCollection();
-
- if (null === $data) {
- return $collection;
- }
-
- foreach ($data as $item) {
- $collection->add(null, $this->hydrate(new $class(), $item));
- }
-
- return $collection;
- }
-
/**
* Create a result collection
*
- * @param array $data
- * @param string $method
- * @return ResultCollection
+ * @param null|array $data
+ * @param string $method
+ * @return ResultCollection
*/
- public function createResultCollection($data = [], $method = 'create')
+ public function createResultCollection($data = [], $method = 'create'): ResultCollection
{
+ /** @var ResultCollection */
$collection = new ResultCollection();
if (null === $data) {
@@ -134,76 +107,73 @@ public function createResultCollection($data = [], $method = 'create')
}
/**
- * Create a generic collection of data and map it on the class by it's static parameter $properties
+ * Create rating
*
- * @param array $data
- * @param AbstractModel $class
- * @param GenericCollection $collection
- * @return GenericCollection
+ * @param array $data
+ * @return Rating
*/
- protected function createCustomCollection($data = [], $class, $collection)
+ public function createRating(array $data = [])
{
- if (is_object($class)) {
- $class = get_class($class);
- }
-
- if (null === $data) {
- return $collection;
- }
-
- foreach ($data as $item) {
- $collection->add(null, $this->hydrate(new $class(), $item));
- }
-
- return $collection;
+ return $this->hydrate(new Rating(), $data);
}
/**
- * Create an generic collection of an array that consists out of a mix of movies and tv shows
+ * Hydrate the object with data
+ *
+ * @template S of AbstractModel
*
- * @param array $data
- * @return GenericCollection
+ * @param S $subject
+ * @param array $data
+ * @return S
*/
- protected function createGenericCollectionFromMediaTypes($data = [])
+ protected function hydrate(AbstractModel $subject, $data = [])
{
- $movieFactory = new MovieFactory($this->getHttpClient());
- $tvFactory = new TvFactory($this->getHttpClient());
- $collection = new GenericCollection();
+ $httpClient = $this->getHttpClient();
+ $hydrationOptions = $this->getHttpClient()->getOptions('hydration');
- foreach ($data as $item) {
- switch ($item['media_type']) {
- case "movie":
- $collection->add(null, $movieFactory->create($item));
- break;
+ $eventListenerHandlesHydration = $hydrationOptions['event_listener_handles_hydration'];
+ $eventBasedHydrationModels = $hydrationOptions['only_for_specified_models'];
- case "tv":
- $collection->add(null, $tvFactory->create($item));
- break;
+ if (
+ $eventListenerHandlesHydration && empty($eventBasedHydrationModels) || in_array(
+ get_class($subject),
+ $eventBasedHydrationModels
+ )
+ ) {
+ $event = new HydrationEvent($subject, $data);
+ $event->setLastRequest($httpClient->getLastRequest());
+ $event->setLastResponse($httpClient->getLastResponse());
- default:
- throw new \RuntimeException('Unknown media type "%s"', $item['media_type']);
- }
+ $this->getHttpClient()->getEventDispatcher()->dispatch($event);
+
+ return $event->getSubject();
}
- return $collection;
+ // Still fire the before hydration event.
+ $event = new BeforeHydrationEvent($subject, $data);
+ $event->setLastRequest($httpClient->getLastRequest());
+ $event->setLastResponse($httpClient->getLastResponse());
+
+ $this->getHttpClient()->getEventDispatcher()->dispatch($event);
+
+ return (new ObjectHydrator())->hydrate($subject, $data);
}
/**
- * Create rating
+ * Get the http client
*
- * @param array $data
- * @return \Tmdb\Model\AbstractModel
+ * @return HttpClient
*/
- public function createRating(array $data = [])
+ protected function getHttpClient()
{
- return $this->hydrate(new Rating(), $data);
+ return $this->httpClient;
}
/**
* Create the account states
*
- * @param array $data
- * @return \Tmdb\Model\AbstractModel
+ * @param array $data
+ * @return AccountStates
*/
public function createAccountStates(array $data = [])
{
@@ -225,8 +195,8 @@ public function createAccountStates(array $data = [])
/**
* Create result
*
- * @param array $data
- * @return \Tmdb\Model\AbstractModel
+ * @param array $data
+ * @return Result
*/
public function createResult(array $data = [])
{
@@ -234,22 +204,91 @@ public function createResult(array $data = [])
}
/**
- * Hydrate the object with data
+ * Create a generic collection of data and map it on the class by it's static parameter $properties
+ *
+ * @template S of AbstractModel
+ * @param array $data
+ * @param S|string $class
*
- * @param AbstractModel $subject
- * @param array $data
- * @return AbstractModel
+ * @return GenericCollection
*/
- protected function hydrate(AbstractModel $subject, $data = [])
+ protected function createGenericCollection(array $data = [], $class = null): GenericCollection
{
- $httpClient = $this->getHttpClient();
+ if (!$class) {
+ throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
+ }
- $event = new HydrationEvent($subject, $data);
- $event->setLastRequest($httpClient->getLastRequest());
- $event->setLastResponse($httpClient->getLastResponse());
+ if (is_object($class)) {
+ $class = get_class($class);
+ }
+
+ /** @var GenericCollection */
+ $collection = new GenericCollection();
+
+ foreach ($data as $item) {
+ $collection->add(null, $this->hydrate(new $class(), $item));
+ }
- $this->getHttpClient()->getEventDispatcher()->dispatch($event, TmdbEvents::HYDRATE);
+ return $collection;
+ }
+
+ /**
+ * Create a generic collection of data and map it on the class by it's static parameter $properties
+ *
+ * @template S of AbstractModel
+ * @template SC of GenericCollection
+ * @param array $data
+ * @param S|string $class
+ * @param SC $collection
+ * @return SC
+ */
+ protected function createCustomCollection(
+ array $data,
+ $class,
+ GenericCollection $collection
+ ) {
+ if (!$class) {
+ throw new \Tmdb\Exception\RuntimeException('Expected a class to be present.');
+ }
- return $event->getSubject();
+ if (is_object($class)) {
+ $class = get_class($class);
+ }
+
+ foreach ($data as $item) {
+ $collection->add(null, $this->hydrate(new $class(), $item));
+ }
+
+ return $collection;
+ }
+
+ /**
+ * Create an generic collection of an array that consists out of a mix of movies and tv shows
+ *
+ * @param array $data
+ * @return GenericCollection
+ */
+ protected function createGenericCollectionFromMediaTypes($data = [])
+ {
+ $movieFactory = new MovieFactory($this->getHttpClient());
+ $tvFactory = new TvFactory($this->getHttpClient());
+ $collection = new GenericCollection();
+
+ foreach ($data as $item) {
+ switch ($item['media_type']) {
+ case "movie":
+ $collection->add(null, $movieFactory->create($item));
+ break;
+
+ case "tv":
+ $collection->add(null, $tvFactory->create($item));
+ break;
+
+ default:
+ throw new RuntimeException('Unknown media type "%s"', $item['media_type']);
+ }
+ }
+
+ return $collection;
}
}
diff --git a/lib/Tmdb/Factory/Account/AvatarFactory.php b/lib/Tmdb/Factory/Account/AvatarFactory.php
index 5289e760..f345ab32 100644
--- a/lib/Tmdb/Factory/Account/AvatarFactory.php
+++ b/lib/Tmdb/Factory/Account/AvatarFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory\Account;
use Tmdb\Exception\InvalidArgumentException;
@@ -23,16 +25,37 @@
*/
class AvatarFactory extends AbstractFactory
{
+ /**
+ * {@inheritdoc}
+ */
+ public function createCollection(array $data = []): GenericCollection
+ {
+ // @todo 4.0.x double check on this bug
+ if (array_key_exists(0, $data)) {
+ $data = $data[0];
+ }
+
+ $collection = new GenericCollection();
+ $collection->add(null, $this->create($data));
+
+ return $collection;
+ }
+
/**
* @param array $data
*
+ * @return mixed
* @throws InvalidArgumentException
*
- * @return mixed
*/
public function create(array $data = [])
{
foreach ($data as $type => $content) {
+ // @todo 4.0.x double check on this bug
+ if (array_key_exists(0, $content)) {
+ $content = array_shift($content);
+ }
+
switch ($type) {
case "gravatar":
return $this->hydrate(new Gravatar(), $content);
@@ -48,15 +71,4 @@ public function create(array $data = [])
return null;
}
-
- /**
- * {@inheritdoc}
- */
- public function createCollection(array $data = [])
- {
- $collection = new GenericCollection();
- $collection->add(null, $this->create($data));
-
- return $collection;
- }
}
diff --git a/lib/Tmdb/Factory/AccountFactory.php b/lib/Tmdb/Factory/AccountFactory.php
index 0c53991b..b56abba8 100644
--- a/lib/Tmdb/Factory/AccountFactory.php
+++ b/lib/Tmdb/Factory/AccountFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
+use RuntimeException;
use Tmdb\Factory\Account\AvatarFactory;
use Tmdb\HttpClient\HttpClient;
+use Tmdb\Model\AbstractModel;
use Tmdb\Model\Account;
use Tmdb\Model\Lists\Result;
/**
* Class AccountFactory
+ * @extends AbstractFactory
* @package Tmdb\Factory
*/
class AccountFactory extends AbstractFactory
@@ -38,6 +43,11 @@ class AccountFactory extends AbstractFactory
*/
private $tvFactory;
+ /**
+ * @var AvatarFactory
+ */
+ private $avatarFactory;
+
/**
* Constructor
*
@@ -45,9 +55,9 @@ class AccountFactory extends AbstractFactory
*/
public function __construct(HttpClient $httpClient)
{
- $this->movieFactory = new MovieFactory($httpClient);
- $this->imageFactory = new ImageFactory($httpClient);
- $this->tvFactory = new TvFactory($httpClient);
+ $this->movieFactory = new MovieFactory($httpClient);
+ $this->imageFactory = new ImageFactory($httpClient);
+ $this->tvFactory = new TvFactory($httpClient);
$this->avatarFactory = new AvatarFactory($httpClient);
parent::__construct($httpClient);
@@ -58,7 +68,7 @@ public function __construct(HttpClient $httpClient)
*
* @return Account
*/
- public function create(array $data = [])
+ public function create(array $data = []): Account
{
$account = new Account();
@@ -71,6 +81,14 @@ public function create(array $data = [])
return $this->hydrate($account, $data);
}
+ /**
+ * @return AvatarFactory
+ */
+ public function getAvatarFactory()
+ {
+ return $this->avatarFactory;
+ }
+
/**
* @param array $data
*
@@ -84,86 +102,84 @@ public function createStatusResult(array $data = [])
/**
* Create movie
*
- * @param array $data
- * @return \Tmdb\Model\Movie
+ * @param array $data
+ *
+ * @return AbstractModel|null
*/
- public function createMovie(array $data = [])
+ public function createMovie(array $data = []): ?AbstractModel
{
return $this->getMovieFactory()->create($data);
}
/**
- * Create TV show
- *
- * @param array $data
- * @return \Tmdb\Model\Tv
+ * @return MovieFactory
*/
- public function createTvShow(array $data = [])
+ public function getMovieFactory()
{
- return $this->getTvFactory()->create($data);
+ return $this->movieFactory;
}
/**
- * Create list item
- *
- * @param array $data
- * @return \Tmdb\Model\AbstractModel
+ * @param MovieFactory $movieFactory
+ * @return self
*/
- public function createListItem(array $data = [])
+ public function setMovieFactory($movieFactory)
{
- $listItem = new Account\ListItem();
-
- if (array_key_exists('poster_path', $data)) {
- $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
- }
+ $this->movieFactory = $movieFactory;
- return $this->hydrate($listItem, $data);
+ return $this;
}
/**
- * {@inheritdoc}
+ * Create TV show
+ *
+ * @param array $data
+ *
+ * @return AbstractModel|null
*/
- public function createCollection(array $data = [])
+ public function createTvShow(array $data = []): ?AbstractModel
{
- throw new \RuntimeException(sprintf(
- 'Class "%s" does not support method "%s".',
- __CLASS__,
- __METHOD__
- ));
+ return $this->getTvFactory()->create($data);
}
/**
- * @param \Tmdb\Factory\MovieFactory $movieFactory
- * @return $this
+ * @return TvFactory
*/
- public function setMovieFactory($movieFactory)
+ public function getTvFactory()
{
- $this->movieFactory = $movieFactory;
-
- return $this;
+ return $this->tvFactory;
}
/**
- * @return \Tmdb\Factory\MovieFactory
+ * @param TvFactory $tvFactory
+ * @return self
*/
- public function getMovieFactory()
+ public function setTvFactory($tvFactory)
{
- return $this->movieFactory;
+ $this->tvFactory = $tvFactory;
+
+ return $this;
}
/**
- * @param \Tmdb\Factory\ImageFactory $imageFactory
- * @return $this
+ * Create list item
+ *
+ * @param array $data
+ * @return AbstractModel
*/
- public function setImageFactory($imageFactory)
+ public function createListItem(array $data = [])
{
- $this->imageFactory = $imageFactory;
+ $listItem = new Account\ListItem();
- return $this;
+ if (array_key_exists('poster_path', $data)) {
+ $listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
+ }
+
+ return $this->hydrate($listItem, $data);
}
/**
- * @return \Tmdb\Factory\ImageFactory
+ * @return ImageFactory
*/
public function getImageFactory()
{
@@ -171,27 +187,31 @@ public function getImageFactory()
}
/**
- * @param \Tmdb\Factory\TvFactory $tvFactory
- * @return $this
+ * @param ImageFactory $imageFactory
+ * @return self
*/
- public function setTvFactory($tvFactory)
+ public function setImageFactory($imageFactory)
{
- $this->tvFactory = $tvFactory;
+ $this->imageFactory = $imageFactory;
return $this;
}
/**
- * @return \Tmdb\Factory\TvFactory
+ * {@inheritdoc}
*/
- public function getTvFactory()
+ public function createCollection(array $data = [])
{
- return $this->tvFactory;
+ throw new RuntimeException(sprintf(
+ 'Class "%s" does not support method "%s".',
+ __CLASS__,
+ __METHOD__
+ ));
}
/**
- * @param \Tmdb\Factory\Account\AvatarFactory $avatarFactory
- * @return $this
+ * @param AvatarFactory $avatarFactory
+ * @return self
*/
public function setAvatarFactory($avatarFactory)
{
@@ -199,12 +219,4 @@ public function setAvatarFactory($avatarFactory)
return $this;
}
-
- /**
- * @return \Tmdb\Factory\Account\AvatarFactory
- */
- public function getAvatarFactory()
- {
- return $this->avatarFactory;
- }
}
diff --git a/lib/Tmdb/Factory/AuthenticationFactory.php b/lib/Tmdb/Factory/AuthenticationFactory.php
index eaf8fe39..fef26d0e 100644
--- a/lib/Tmdb/Factory/AuthenticationFactory.php
+++ b/lib/Tmdb/Factory/AuthenticationFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
-use Tmdb\GuestSessionToken;
-use Tmdb\RequestToken;
-use Tmdb\SessionToken;
+use DateTime;
+use RuntimeException;
+use Tmdb\Model\AbstractModel;
+use Tmdb\Model\Common\GenericCollection;
+use Tmdb\Token\Session\GuestSessionToken;
+use Tmdb\Token\Session\RequestToken;
+use Tmdb\Token\Session\SessionToken;
/**
* Class AuthenticationFactory
@@ -25,12 +31,12 @@ class AuthenticationFactory extends AbstractFactory
/**
* @param array $data
*
- * @throws \RuntimeException
- * @return void
+ * @return AbstractModel
+ * @throws RuntimeException
*/
public function create(array $data = [])
{
- throw new \RuntimeException(sprintf(
+ throw new RuntimeException(sprintf(
'Class "%s" does not support method "%s".',
__CLASS__,
__METHOD__
@@ -40,12 +46,12 @@ public function create(array $data = [])
/**
* @param array $data
*
- * @throws \RuntimeException
- * @return void
+ * @return GenericCollection
+ * @throws RuntimeException
*/
public function createCollection(array $data = [])
{
- throw new \RuntimeException(sprintf(
+ throw new RuntimeException(sprintf(
'Class "%s" does not support method "%s".',
__CLASS__,
__METHOD__
@@ -55,7 +61,7 @@ public function createCollection(array $data = [])
/**
* Create request token
*
- * @param array $data
+ * @param array $data
* @return RequestToken
*/
public function createRequestToken(array $data = [])
@@ -63,7 +69,7 @@ public function createRequestToken(array $data = [])
$token = new RequestToken();
if (array_key_exists('expires_at', $data)) {
- $token->setExpiresAt(new \DateTime($data['expires_at']));
+ $token->setExpiresAt(new DateTime($data['expires_at']));
}
if (array_key_exists('request_token', $data)) {
@@ -80,7 +86,7 @@ public function createRequestToken(array $data = [])
/**
* Create session token for user
*
- * @param array $data
+ * @param array $data
* @return SessionToken
*/
public function createSessionToken(array $data = [])
@@ -101,15 +107,15 @@ public function createSessionToken(array $data = [])
/**
* Create session token for guest
*
- * @param array $data
- * @return SessionToken
+ * @param array $data
+ * @return GuestSessionToken
*/
public function createGuestSessionToken(array $data = [])
{
$token = new GuestSessionToken();
if (array_key_exists('expires_at', $data)) {
- $token->setExpiresAt(new \DateTime($data['expires_at']));
+ $token->setExpiresAt(new DateTime($data['expires_at']));
}
if (array_key_exists('guest_session_id', $data)) {
diff --git a/lib/Tmdb/Factory/CertificationFactory.php b/lib/Tmdb/Factory/CertificationFactory.php
index 59ac727d..a27234ef 100644
--- a/lib/Tmdb/Factory/CertificationFactory.php
+++ b/lib/Tmdb/Factory/CertificationFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
use Tmdb\Model\Certification;
@@ -21,20 +23,10 @@
*/
class CertificationFactory extends AbstractFactory
{
- /**
- * @param array $data
- *
- * @return Certification
- */
- public function create(array $data = [])
- {
- return $this->hydrate(new Certification\CountryCertification(), $data);
- }
-
/**
* {@inheritdoc}
*/
- public function createCollection(array $data = [])
+ public function createCollection(array $data = []): GenericCollection
{
if (array_key_exists('certifications', $data)) {
$data = $data['certifications'];
@@ -57,4 +49,14 @@ public function createCollection(array $data = [])
return $collection;
}
+
+ /**
+ * @param array $data
+ *
+ * @return Certification\CountryCertification
+ */
+ public function create(array $data = []): Certification\CountryCertification
+ {
+ return $this->hydrate(new Certification\CountryCertification(), $data);
+ }
}
diff --git a/lib/Tmdb/Factory/ChangesFactory.php b/lib/Tmdb/Factory/ChangesFactory.php
index 7344552a..71064d2a 100644
--- a/lib/Tmdb/Factory/ChangesFactory.php
+++ b/lib/Tmdb/Factory/ChangesFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
use Tmdb\Model\Change;
@@ -21,19 +23,10 @@
*/
class ChangesFactory extends AbstractFactory
{
- /**
- * {@inheritdoc}
- * @return \Tmdb\Model\Change
- */
- public function create(array $data = [])
- {
- return $this->hydrate(new Change(), $data);
- }
-
/**
* {@inheritdoc}
*/
- public function createCollection(array $data = [])
+ public function createCollection(array $data = []): Changes
{
$collection = new Changes();
@@ -59,4 +52,13 @@ public function createCollection(array $data = [])
return $collection;
}
+
+ /**
+ * {@inheritdoc}
+ * @return Change
+ */
+ public function create(array $data = []): Change
+ {
+ return $this->hydrate(new Change(), $data);
+ }
}
diff --git a/lib/Tmdb/Factory/CollectionFactory.php b/lib/Tmdb/Factory/CollectionFactory.php
index b87c752d..d870e3eb 100644
--- a/lib/Tmdb/Factory/CollectionFactory.php
+++ b/lib/Tmdb/Factory/CollectionFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory;
use Tmdb\HttpClient\HttpClient;
@@ -48,9 +50,23 @@ public function __construct(HttpClient $httpClient)
/**
* {@inheritdoc}
- * @return \Tmdb\Model\Collection
*/
- public function create(array $data = [])
+ public function createCollection(array $data = []): GenericCollection
+ {
+ $collection = new GenericCollection();
+
+ foreach ($data as $item) {
+ $collection->add(null, $this->create($item));
+ }
+
+ return $collection;
+ }
+
+ /**
+ * {@inheritdoc}
+ * @return Collection
+ */
+ public function create(array $data = []): Collection
{
$collection = new Collection();
@@ -95,32 +111,26 @@ public function create(array $data = [])
}
/**
- * {@inheritdoc}
+ * @return MovieFactory
*/
- public function createCollection(array $data = [])
+ public function getMovieFactory()
{
- $collection = new GenericCollection();
-
- foreach ($data as $item) {
- $collection->add(null, $this->create($item));
- }
-
- return $collection;
+ return $this->movieFactory;
}
/**
- * @param \Tmdb\Factory\ImageFactory $imageFactory
- * @return $this
+ * @param MovieFactory $movieFactory
+ * @return self
*/
- public function setImageFactory($imageFactory)
+ public function setMovieFactory($movieFactory)
{
- $this->imageFactory = $imageFactory;
+ $this->movieFactory = $movieFactory;
return $this;
}
/**
- * @return \Tmdb\Factory\ImageFactory
+ * @return ImageFactory
*/
public function getImageFactory()
{
@@ -128,21 +138,13 @@ public function getImageFactory()
}
/**
- * @param \Tmdb\Factory\MovieFactory $movieFactory
- * @return $this
+ * @param ImageFactory $imageFactory
+ * @return self
*/
- public function setMovieFactory($movieFactory)
+ public function setImageFactory($imageFactory)
{
- $this->movieFactory = $movieFactory;
+ $this->imageFactory = $imageFactory;
return $this;
}
-
- /**
- * @return \Tmdb\Factory\MovieFactory
- */
- public function getMovieFactory()
- {
- return $this->movieFactory;
- }
}
diff --git a/lib/Tmdb/Factory/Common/ChangeFactory.php b/lib/Tmdb/Factory/Common/ChangeFactory.php
index 77263cf5..c06645b7 100644
--- a/lib/Tmdb/Factory/Common/ChangeFactory.php
+++ b/lib/Tmdb/Factory/Common/ChangeFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory\Common;
use Tmdb\Factory\AbstractFactory;
+use Tmdb\Model\AbstractModel;
+use Tmdb\Model\Collection\Changes;
use Tmdb\Model\Common\Change;
use Tmdb\Model\Common\GenericCollection;
@@ -25,7 +29,25 @@ class ChangeFactory extends AbstractFactory
/**
* {@inheritdoc}
*/
- public function create(array $data = [])
+ public function createCollection(array $data = []): Changes
+ {
+ $collection = new Changes();
+
+ if (array_key_exists('changes', $data)) {
+ $data = $data['changes'];
+ }
+
+ foreach ($data as $item) {
+ $collection->add(null, $this->create($item));
+ }
+
+ return $collection;
+ }
+
+ /**
+ * {@inheritdoc}
+ */
+ public function create(array $data = []): Change
{
$change = new Change();
@@ -47,29 +69,11 @@ public function create(array $data = [])
/**
* Create individual change items
*
- * @param array $data
- * @return \Tmdb\Model\AbstractModel
+ * @param array $data
+ * @return Change\Item
*/
- private function createChangeItem(array $data = [])
+ private function createChangeItem(array $data = []): Change\Item
{
return $this->hydrate(new Change\Item(), $data);
}
-
- /**
- * {@inheritdoc}
- */
- public function createCollection(array $data = [])
- {
- $collection = new GenericCollection();
-
- if (array_key_exists('changes', $data)) {
- $data = $data['changes'];
- }
-
- foreach ($data as $item) {
- $collection->add(null, $this->create($item));
- }
-
- return $collection;
- }
}
diff --git a/lib/Tmdb/Factory/Common/GenericCollectionFactory.php b/lib/Tmdb/Factory/Common/GenericCollectionFactory.php
deleted file mode 100644
index 38fe2d67..00000000
--- a/lib/Tmdb/Factory/Common/GenericCollectionFactory.php
+++ /dev/null
@@ -1,56 +0,0 @@
-
- * @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
- */
-namespace Tmdb\Factory\Common;
-
-use Tmdb\Common\ObjectHydrator;
-use Tmdb\Model\Common\GenericCollection;
-
-/**
- * @deprecated
- *
- * Class GenericCollectionFactory
- * @package Tmdb\Factory\Common
- */
-class GenericCollectionFactory
-{
- /**
- * @param array $data
- * @param $class
- * @return GenericCollection
- */
- public function create(array $data, $class)
- {
- return $this->createCollection($data, $class);
- }
-
- /**
- * @param array $data
- * @param $class
- * @return GenericCollection
- */
- public function createCollection(array $data, $class)
- {
- if (is_object($class)) {
- $class = get_class($class);
- }
-
- $collection = new GenericCollection();
- $objectHydrator = new ObjectHydrator();
-
- foreach ($data as $item) {
- $collection->add(null, $objectHydrator->hydrate(new $class(), $item));
- }
-
- return $collection;
- }
-}
diff --git a/lib/Tmdb/Factory/Common/VideoFactory.php b/lib/Tmdb/Factory/Common/VideoFactory.php
index 63e4866d..887a114a 100644
--- a/lib/Tmdb/Factory/Common/VideoFactory.php
+++ b/lib/Tmdb/Factory/Common/VideoFactory.php
@@ -1,4 +1,5 @@
* @copyright (c) 2013, Michael Roterman
- * @version 0.0.1
+ * @version 4.0.0
*/
+
namespace Tmdb\Factory\Common;
use Tmdb\Factory\AbstractFactory;
+use Tmdb\Model\AbstractModel;
use Tmdb\Model\Collection\Videos;
use Tmdb\Model\Common\Video;
/**
* Class VideoFactory
+ * @extends AbstractFactory