From 53b2fb068d85954cfea5ee3c29aaa67f11f8bff6 Mon Sep 17 00:00:00 2001 From: Michael Roterman Date: Sat, 11 Jan 2014 22:30:39 +0100 Subject: [PATCH] Refactoring API namespace and expanding the Model namespace. - Adding $headers parameter to all API methods - Modified client class, remove the api() method - Adding repositories - Cleaning up model classes --- examples/genres/model/get.php | 11 +- examples/movies/model/all.php | 21 +- examples/people/model/all.php | 13 +- lib/Tmdb/Api/Account.php | 21 +- lib/Tmdb/Api/Authentication.php | 9 +- lib/Tmdb/Api/Changes.php | 10 +- lib/Tmdb/Api/Collections.php | 10 +- lib/Tmdb/Api/Companies.php | 10 +- lib/Tmdb/Api/Configuration.php | 5 +- lib/Tmdb/Api/Discover.php | 4 +- lib/Tmdb/Api/Genres.php | 13 +- lib/Tmdb/Api/Jobs.php | 5 +- lib/Tmdb/Api/Keywords.php | 10 +- lib/Tmdb/Api/Lists.php | 20 +- lib/Tmdb/Api/Movies.php | 91 ++++--- lib/Tmdb/Api/People.php | 32 ++- lib/Tmdb/Api/Reviews.php | 5 +- lib/Tmdb/Api/Search.php | 35 +-- lib/Tmdb/Api/Tv.php | 22 +- lib/Tmdb/Api/TvEpisode.php | 20 +- lib/Tmdb/Api/TvSeason.php | 10 +- lib/Tmdb/Client.php | 232 +++++++++--------- lib/Tmdb/Factory/ConfigurationFactory.php | 1 - lib/Tmdb/Factory/GenreFactory.php | 18 +- .../Factory/{Common => }/ImageFactory.php | 5 +- lib/Tmdb/Factory/MovieFactory.php | 2 - lib/Tmdb/{Model => }/Helper/ImageHelper.php | 29 ++- lib/Tmdb/Model/AbstractModel.php | 43 +--- .../Model/{Common => }/Collection/Images.php | 2 +- lib/Tmdb/Model/Image.php | 69 ++---- lib/Tmdb/Model/Movie.php | 2 +- lib/Tmdb/Model/Person.php | 33 --- lib/Tmdb/Repository/AbstractRepository.php | 18 +- .../Repository/ConfigurationRepository.php | 7 +- lib/Tmdb/Repository/GenreRepository.php | 88 +++++++ lib/Tmdb/Repository/MovieRepository.php | 40 +-- ...sonRepository.php => PeopleRepository.php} | 28 ++- 37 files changed, 544 insertions(+), 450 deletions(-) rename lib/Tmdb/Factory/{Common => }/ImageFactory.php (94%) rename lib/Tmdb/{Model => }/Helper/ImageHelper.php (59%) rename lib/Tmdb/Model/{Common => }/Collection/Images.php (96%) create mode 100644 lib/Tmdb/Repository/GenreRepository.php rename lib/Tmdb/Repository/{PersonRepository.php => PeopleRepository.php} (59%) diff --git a/examples/genres/model/get.php b/examples/genres/model/get.php index 5c490164..7387ae8c 100644 --- a/examples/genres/model/get.php +++ b/examples/genres/model/get.php @@ -16,6 +16,13 @@ $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token); -$genre = \Tmdb\Model\Genre::load($client, 28); +$repository = new \Tmdb\Repository\GenreRepository($client); +$genre = $repository->load(28); -echo $genre->getName(); \ No newline at end of file +var_dump($genre); + +$genres = $repository->loadCollection(); + +foreach($genres as $genre) { + var_dump($genre); +} \ No newline at end of file diff --git a/examples/movies/model/all.php b/examples/movies/model/all.php index ec87474d..82c26f99 100644 --- a/examples/movies/model/all.php +++ b/examples/movies/model/all.php @@ -18,23 +18,8 @@ $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token); -// This is optional, but if you want lots of data this is the way. -$append = new \Tmdb\Model\Movie\QueryParameter\AppendToResponse(array( - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::ALTERNATIVE_TITLES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::CHANGES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::CREDITS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::IMAGES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::KEYWORDS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::LISTS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::RELEASES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::REVIEWS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::SIMILAR_MOVIES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRAILERS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS, -)); - $repository = new \Tmdb\Repository\MovieRepository($client); -$movie = $repository->load(87421, array($append)); +$movie = $repository->load(87421); echo $movie->getTitle() . "
"; @@ -61,11 +46,11 @@ $configRepository = new \Tmdb\Repository\ConfigurationRepository($client); $config = $configRepository->load(); -$imageHelper = new \Tmdb\Model\Helper\ImageHelper($config); +$imageHelper = new \Tmdb\Helper\ImageHelper($config); foreach($movie->getImages() as $image) { echo $imageHelper->getHtml($image); - printf(" - %s
", $image->getFilePath()); + printf(" - %s
", $imageHelper->getUrl($image)); } echo "Genres
"; diff --git a/examples/people/model/all.php b/examples/people/model/all.php index c922b2e9..11c08e70 100644 --- a/examples/people/model/all.php +++ b/examples/people/model/all.php @@ -16,18 +16,7 @@ $token = new \Tmdb\ApiToken(TMDB_API_KEY); $client = new \Tmdb\Client($token); -// This is optional, but if you want lots of data this is the way. -$append = new \Tmdb\Model\Person\QueryParameter\AppendToResponse(array( - \Tmdb\Model\Person\QueryParameter\AppendToResponse::IMAGES, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::CHANGES, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::COMBINED_CREDITS, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::LATEST, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::MOVIE_CREDITS, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::TV_CREDITS, - \Tmdb\Model\Person\QueryParameter\AppendToResponse::POPULAR -)); - $repository = new \Tmdb\Repository\PersonRepository($client); -$person = $repository->load(33, array($append)); +$person = $repository->load(33); var_dump($person); \ No newline at end of file diff --git a/lib/Tmdb/Api/Account.php b/lib/Tmdb/Api/Account.php index a62fd0c7..0c74abc7 100644 --- a/lib/Tmdb/Api/Account.php +++ b/lib/Tmdb/Api/Account.php @@ -21,10 +21,11 @@ class Account * Get the basic information for an account. You will need to have a valid session id. * * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getAccount(array $options = array()) + public function getAccount(array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -34,10 +35,11 @@ public function getAccount(array $options = array()) * * @param $account_id * @param $options array + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getLists($account_id, array $options = array()) + public function getLists($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -47,10 +49,11 @@ public function getLists($account_id, array $options = array()) * * @param $account_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getFavoriteMovies($account_id, array $options = array()) + public function getFavoriteMovies($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -60,10 +63,11 @@ public function getFavoriteMovies($account_id, array $options = array()) * * @param $account_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function favorite($account_id, array $options = array()) + public function favorite($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -73,10 +77,11 @@ public function favorite($account_id, array $options = array()) * * @param $account_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getRatedMovies($account_id, array $options = array()) + public function getRatedMovies($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -86,10 +91,11 @@ public function getRatedMovies($account_id, array $options = array()) * * @param $account_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getMovieWatchlist($account_id, array $options = array()) + public function getMovieWatchlist($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -99,10 +105,11 @@ public function getMovieWatchlist($account_id, array $options = array()) * * @param $account_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function watchlist($account_id, array $options = array()) + public function watchlist($account_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } diff --git a/lib/Tmdb/Api/Authentication.php b/lib/Tmdb/Api/Authentication.php index 379fab08..30cb5af5 100644 --- a/lib/Tmdb/Api/Authentication.php +++ b/lib/Tmdb/Api/Authentication.php @@ -25,10 +25,11 @@ class Authentication * As soon as a valid session id has been created the token will be destroyed. * * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getNewToken(array $options = array()) + public function getNewToken(array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -39,10 +40,11 @@ public function getNewToken(array $options = array()) * * @param $request_token * @param $options array + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getNewSession($request_token, array $options = array()) + public function getNewSession($request_token, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -59,10 +61,11 @@ public function getNewSession($request_token, array $options = array()) * If a guest session is not used for the first time within 24 hours, it will be automatically discarded. * * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getNewGuestSession(array $options = array()) + public function getNewGuestSession(array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } diff --git a/lib/Tmdb/Api/Changes.php b/lib/Tmdb/Api/Changes.php index f34ce1aa..55026fcc 100644 --- a/lib/Tmdb/Api/Changes.php +++ b/lib/Tmdb/Api/Changes.php @@ -27,11 +27,12 @@ class Changes * on October 5, 2012 and will only show movies that have been edited since. * * @param array $options + * @param array $headers * @return mixed */ - public function getMovieChanges(array $options = array()) + public function getMovieChanges(array $options = array(), array $headers = array()) { - return $this->get('movie/changes', $options); + return $this->get('movie/changes', $options, $headers); } /** @@ -46,10 +47,11 @@ public function getMovieChanges(array $options = array()) * on October 5, 2012 and will only show movies that have been edited since. * * @param array $options + * @param array $headers * @return mixed */ - public function getPeopleChanges(array $options = array()) + public function getPeopleChanges(array $options = array(), array $headers = array()) { - return $this->get('person/changes', $options); + return $this->get('person/changes', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Collections.php b/lib/Tmdb/Api/Collections.php index a7813c79..eda6b862 100644 --- a/lib/Tmdb/Api/Collections.php +++ b/lib/Tmdb/Api/Collections.php @@ -26,11 +26,12 @@ class Collections * * @param $collection_id * @param array $options + * @param array $headers * @return mixed */ - public function getCollection($collection_id, array $options = array()) + public function getCollection($collection_id, array $options = array(), array $headers = array()) { - return $this->get('collection/' . $collection_id, $options); + return $this->get('collection/' . $collection_id, $options, $headers); } /** @@ -38,10 +39,11 @@ public function getCollection($collection_id, array $options = array()) * * @param $collection_id * @param array $options + * @param array $headers * @return mixed */ - public function getImages($collection_id, array $options = array()) + public function getImages($collection_id, array $options = array(), array $headers = array()) { - return $this->get('collection/' . $collection_id . '/images', $options); + return $this->get('collection/' . $collection_id . '/images', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Companies.php b/lib/Tmdb/Api/Companies.php index 1c5a58da..190755ce 100644 --- a/lib/Tmdb/Api/Companies.php +++ b/lib/Tmdb/Api/Companies.php @@ -20,11 +20,12 @@ class Companies * * @param $company_id * @param array $options + * @param array $headers * @return mixed */ - public function getCompany($company_id, array $options = array()) + public function getCompany($company_id, array $options = array(), array $headers = array()) { - return $this->get('company/' . $company_id, $options); + return $this->get('company/' . $company_id, $options, $headers); } /** @@ -32,10 +33,11 @@ public function getCompany($company_id, array $options = array()) * * @param $company_id * @param array $options + * @param array $headers * @return mixed */ - public function getMovies($company_id, array $options = array()) + public function getMovies($company_id, array $options = array(), array $headers = array()) { - return $this->get('company/' . $company_id . '/movies', $options); + return $this->get('company/' . $company_id . '/movies', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Configuration.php b/lib/Tmdb/Api/Configuration.php index ad760555..b78528e1 100644 --- a/lib/Tmdb/Api/Configuration.php +++ b/lib/Tmdb/Api/Configuration.php @@ -32,10 +32,11 @@ class Configuration * * http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/8uO0gUM8aNqYLs1OsTBQiXu0fEv.jpg * + * @param array $headers * @return mixed */ - public function getConfiguration() + public function getConfiguration(array $headers = array()) { - return $this->get('configuration'); + return $this->get('configuration', array(), $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Discover.php b/lib/Tmdb/Api/Discover.php index 6dc14091..4616a86b 100644 --- a/lib/Tmdb/Api/Discover.php +++ b/lib/Tmdb/Api/Discover.php @@ -21,8 +21,8 @@ class Discover * @param array $options * @return mixed */ - public function discoverMovies(array $options = array()) + public function discoverMovies(array $options = array(), array $headers = array()) { - return $this->get('discover/movie', $options); + return $this->get('discover/movie', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Genres.php b/lib/Tmdb/Api/Genres.php index e41295a8..80589024 100644 --- a/lib/Tmdb/Api/Genres.php +++ b/lib/Tmdb/Api/Genres.php @@ -20,9 +20,10 @@ class Genres * * @param integer $id * @param array $options + * @param array $headers * @return mixed */ - public function getGenre($id, array $options = array()) + public function getGenre($id, array $options = array(), array $headers = array()) { $response = $this->getGenres(); @@ -39,11 +40,12 @@ public function getGenre($id, array $options = array()) * Get the list of genres. * * @param array $options + * @param array $headers * @return mixed */ - public function getGenres(array $options = array()) + public function getGenres(array $options = array(), array $headers = array()) { - return $this->get('genre/list', $options); + return $this->get('genre/list', $options, $headers); } /** @@ -51,10 +53,11 @@ public function getGenres(array $options = array()) * * @param $genre_id * @param array $options + * @param array $headers * @return mixed */ - public function getMovies($genre_id, array $options = array()) + public function getMovies($genre_id, array $options = array(), array $headers = array()) { - return $this->get('genre/' . $genre_id . '/movies', $options); + return $this->get('genre/' . $genre_id . '/movies', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Jobs.php b/lib/Tmdb/Api/Jobs.php index 86cf120b..d778d28c 100644 --- a/lib/Tmdb/Api/Jobs.php +++ b/lib/Tmdb/Api/Jobs.php @@ -19,10 +19,11 @@ class Jobs * Get a list of valid jobs. * * @param array $options + * @param array $headers * @return mixed */ - public function getMovieChanges(array $options = array()) + public function getMovieChanges(array $options = array(), array $headers = array()) { - return $this->get('job/list', $options); + return $this->get('job/list', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Keywords.php b/lib/Tmdb/Api/Keywords.php index 5d97210c..f08f0921 100644 --- a/lib/Tmdb/Api/Keywords.php +++ b/lib/Tmdb/Api/Keywords.php @@ -19,11 +19,12 @@ class Keywords * Get the basic information for a specific keyword id. * * @param array $options + * @param array $headers * @return mixed */ - public function getKeywords(array $options = array()) + public function getKeywords(array $options = array(), array $headers = array()) { - return $this->get('keyword/list', $options); + return $this->get('keyword/list', $options, $headers); } /** @@ -31,10 +32,11 @@ public function getKeywords(array $options = array()) * * @param $keyword_id * @param array $options + * @param array $headers * @return mixed */ - public function getMovies($keyword_id, array $options = array()) + public function getMovies($keyword_id, array $options = array(), array $headers = array()) { - return $this->get('keyword/' . $keyword_id . '/movies', $options); + return $this->get('keyword/' . $keyword_id . '/movies', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Lists.php b/lib/Tmdb/Api/Lists.php index 1afe7d89..db9322da 100644 --- a/lib/Tmdb/Api/Lists.php +++ b/lib/Tmdb/Api/Lists.php @@ -22,11 +22,12 @@ class Lists * * @param $list_id * @param array $options + * @param array $headers * @return mixed */ - public function getList($list_id, array $options = array()) + public function getList($list_id, array $options = array(), array $headers = array()) { - return $this->get('list/' . $list_id, $options); + return $this->get('list/' . $list_id, $options, $headers); } /** @@ -35,10 +36,11 @@ public function getList($list_id, array $options = array()) * @param $name * @param $description * @param $options array + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function createList($name, $description, array $options = array()) + public function createList($name, $description, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -49,10 +51,11 @@ public function createList($name, $description, array $options = array()) * @param $list_id * @param $movie_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function getItemStatus($list_id, $movie_id, array $options = array()) + public function getItemStatus($list_id, $movie_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -63,10 +66,11 @@ public function getItemStatus($list_id, $movie_id, array $options = array()) * @param $list_id * @param $media_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function addMediaToList($list_id, $media_id, array $options = array()) + public function addMediaToList($list_id, $media_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -77,10 +81,11 @@ public function addMediaToList($list_id, $media_id, array $options = array()) * @param $list_id * @param $media_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function removeMediaFromList($list_id, $media_id, array $options = array()) + public function removeMediaFromList($list_id, $media_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } @@ -90,10 +95,11 @@ public function removeMediaFromList($list_id, $media_id, array $options = array( * * @param $list_id * @param array $options + * @param array $headers * @throws NotImplementedException * @return mixed */ - public function deleteList($list_id, array $options = array()) + public function deleteList($list_id, array $options = array(), array $headers = array()) { throw new NotImplementedException(__METHOD__ . ' has not been implemented yet.'); } diff --git a/lib/Tmdb/Api/Movies.php b/lib/Tmdb/Api/Movies.php index 5b55af9e..29dd08d1 100644 --- a/lib/Tmdb/Api/Movies.php +++ b/lib/Tmdb/Api/Movies.php @@ -22,11 +22,12 @@ class Movies * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getMovie($movie_id, array $options = array()) + public function getMovie($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id, $options); + return $this->get('movie/' . $movie_id, $options, $headers); } /** @@ -34,11 +35,12 @@ public function getMovie($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getAlternativeTitles($movie_id, array $options = array()) + public function getAlternativeTitles($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/alternative_titles', $options); + return $this->get('movie/' . $movie_id . '/alternative_titles', $options, $headers); } /** @@ -46,11 +48,12 @@ public function getAlternativeTitles($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getCast($movie_id, array $options = array()) + public function getCast($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/casts', $options); + return $this->get('movie/' . $movie_id . '/casts', $options, $headers); } /** @@ -58,11 +61,12 @@ public function getCast($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getImages($movie_id, array $options = array()) + public function getImages($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/images', $options); + return $this->get('movie/' . $movie_id . '/images', $options, $headers); } /** @@ -70,11 +74,12 @@ public function getImages($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getKeywords($movie_id, array $options = array()) + public function getKeywords($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/keywords', $options); + return $this->get('movie/' . $movie_id . '/keywords', $options, $headers); } /** @@ -82,11 +87,12 @@ public function getKeywords($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getReleases($movie_id, array $options = array()) + public function getReleases($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/releases', $options); + return $this->get('movie/' . $movie_id . '/releases', $options, $headers); } /** @@ -94,11 +100,12 @@ public function getReleases($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getTrailers($movie_id, array $options = array()) + public function getTrailers($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/trailers', $options); + return $this->get('movie/' . $movie_id . '/trailers', $options, $headers); } /** @@ -106,11 +113,12 @@ public function getTrailers($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getTranslations($movie_id, array $options = array()) + public function getTranslations($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/translations', $options); + return $this->get('movie/' . $movie_id . '/translations', $options, $headers); } /** @@ -118,11 +126,12 @@ public function getTranslations($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getSimilarMovies($movie_id, array $options = array()) + public function getSimilarMovies($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/similar_movies', $options); + return $this->get('movie/' . $movie_id . '/similar_movies', $options, $headers); } /** @@ -130,11 +139,12 @@ public function getSimilarMovies($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getReviews($movie_id, array $options = array()) + public function getReviews($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/reviews', $options); + return $this->get('movie/' . $movie_id . '/reviews', $options, $headers); } /** @@ -142,11 +152,12 @@ public function getReviews($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getLists($movie_id, array $options = array()) + public function getLists($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/lists', $options); + return $this->get('movie/' . $movie_id . '/lists', $options, $headers); } /** @@ -154,66 +165,72 @@ public function getLists($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @return mixed */ - public function getChanges($movie_id, array $options = array()) + public function getChanges($movie_id, array $options = array(), array $headers = array()) { - return $this->get('movie/' . $movie_id . '/changes', $options); + return $this->get('movie/' . $movie_id . '/changes', $options, $headers); } /** * Get the latest movie id. * * @param array $options + * @param array $headers * @return mixed */ - public function getLatest(array $options = array()) + public function getLatest(array $options = array(), array $headers = array()) { - return $this->get('movie/latest', $options); + return $this->get('movie/latest', $options, $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 $options + * @param array $headers * @return mixed */ - public function getUpcoming(array $options = array()) + public function getUpcoming(array $options = array(), array $headers = array()) { - return $this->get('movie/upcoming', $options); + return $this->get('movie/upcoming', $options, $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 $options + * @param array $headers * @return mixed */ - public function getNowPlaying(array $options = array()) + public function getNowPlaying(array $options = array(), array $headers = array()) { - return $this->get('movie/now_playing', $options); + return $this->get('movie/now_playing', $options, $headers); } /** * Get the list of popular movies on The Movie Database. This list refreshes every day. * * @param array $options + * @param array $headers * @return mixed */ - public function getPopular(array $options = array()) + public function getPopular(array $options = array(), array $headers = array()) { - return $this->get('movie/popular', $options); + return $this->get('movie/popular', $options, $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 $options + * @param array $headers * @return mixed */ - public function getTopRated(array $options = array()) + public function getTopRated(array $options = array(), array $headers = array()) { - return $this->get('movie/top_rated', $options); + return $this->get('movie/top_rated', $options, $headers); } /** @@ -221,9 +238,10 @@ public function getTopRated(array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @throws \Tmdb\Exception\NotImplementedException */ - public function getAccountStates($movie_id, array $options = array()) + public function getAccountStates($movie_id, array $options = array(), array $headers = array()) { throw new NotImplementedException('TMDB account sessions have not been implemented yet!'); } @@ -233,9 +251,10 @@ public function getAccountStates($movie_id, array $options = array()) * * @param $movie_id * @param array $options + * @param array $headers * @throws \Tmdb\Exception\NotImplementedException */ - public function rateMovie($movie_id, array $options = array()) + public function rateMovie($movie_id, array $options = array(), array $headers = array()) { throw new NotImplementedException('TMDB account sessions have not been implemented yet!'); } diff --git a/lib/Tmdb/Api/People.php b/lib/Tmdb/Api/People.php index 6651db13..11243353 100644 --- a/lib/Tmdb/Api/People.php +++ b/lib/Tmdb/Api/People.php @@ -20,11 +20,12 @@ class People * * @param $person_id * @param array $options + * @param array $headers * @return mixed */ - public function getPerson($person_id, array $options = array()) + public function getPerson($person_id, array $options = array(), array $headers = array()) { - return $this->get('person/' . $person_id, $options); + return $this->get('person/' . $person_id, $options, $headers); } /** @@ -32,11 +33,12 @@ public function getPerson($person_id, array $options = array()) * * @param $person_id * @param array $options + * @param array $headers * @return mixed */ - public function getCredits($person_id, array $options = array()) + public function getCredits($person_id, array $options = array(), array $headers = array()) { - return $this->get('person/' . $person_id . '/credits', $options); + return $this->get('person/' . $person_id . '/credits', $options, $headers); } /** @@ -44,11 +46,12 @@ public function getCredits($person_id, array $options = array()) * * @param $person_id * @param array $options + * @param array $headers * @return mixed */ - public function getImages($person_id, array $options = array()) + public function getImages($person_id, array $options = array(), array $headers = array()) { - return $this->get('person/' . $person_id . '/images', $options); + return $this->get('person/' . $person_id . '/images', $options, $headers); } /** @@ -62,30 +65,35 @@ public function getImages($person_id, array $options = array()) * * @param $person_id * @param array $options + * @param array $headers * @return mixed */ - public function getChanges($person_id, array $options = array()) + public function getChanges($person_id, array $options = array(), array $headers = array()) { - return $this->get('person/' . $person_id . '/changes', $options); + return $this->get('person/' . $person_id . '/changes', $options, $headers); } /** * Get the list of popular people on The Movie Database. This list refreshes every day. * + * @param array $options + * @param array $headers * @return mixed */ - public function getPopular() + public function getPopular(array $options = array(), array $headers = array()) { - return $this->get('person/popular'); + return $this->get('person/popular', $options, $headers); } /** * Get the latest person id. * + * @param array $options + * @param array $headers * @return mixed */ - public function getLatest() + public function getLatest(array $options = array(), array $headers = array()) { - return $this->get('person/latest'); + return $this->get('person/latest', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Reviews.php b/lib/Tmdb/Api/Reviews.php index a88bd842..24105449 100644 --- a/lib/Tmdb/Api/Reviews.php +++ b/lib/Tmdb/Api/Reviews.php @@ -20,10 +20,11 @@ class Reviews * * @param $review_id * @param array $options + * @param array $headers * @return mixed */ - public function getReview($review_id, array $options = array()) + public function getReview($review_id, array $options = array(), array $headers = array()) { - return $this->get('review/' . $review_id, $options); + return $this->get('review/' . $review_id, $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Search.php b/lib/Tmdb/Api/Search.php index d5d03378..f79ff994 100644 --- a/lib/Tmdb/Api/Search.php +++ b/lib/Tmdb/Api/Search.php @@ -20,13 +20,14 @@ class Search * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchMovies($query, array $options = array()) + public function searchMovies($query, array $options = array(), array $headers = array()) { return $this->get('search/movie', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -34,13 +35,14 @@ public function searchMovies($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchCollection($query, array $options = array()) + public function searchCollection($query, array $options = array(), array $headers = array()) { return $this->get('search/collection', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -48,13 +50,14 @@ public function searchCollection($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchTv($query, array $options = array()) + public function searchTv($query, array $options = array(), array $headers = array()) { return $this->get('search/tv', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -62,13 +65,14 @@ public function searchTv($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchPersons($query, array $options = array()) + public function searchPersons($query, array $options = array(), array $headers = array()) { return $this->get('search/person', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -76,13 +80,14 @@ public function searchPersons($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchList($query, array $options = array()) + public function searchList($query, array $options = array(), array $headers = array()) { return $this->get('search/list', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -90,13 +95,14 @@ public function searchList($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchCompany($query, array $options = array()) + public function searchCompany($query, array $options = array(), array $headers = array()) { return $this->get('search/company', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } /** @@ -104,12 +110,13 @@ public function searchCompany($query, array $options = array()) * * @param $query * @param array $options + * @param array $headers * @return mixed */ - public function searchKeyword($query, array $options = array()) + public function searchKeyword($query, array $options = array(), array $headers = array()) { return $this->get('search/keyword', array_merge($options, array( 'query' => $query - ))); + ), $headers)); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/Tv.php b/lib/Tmdb/Api/Tv.php index 12d88555..502f96ea 100644 --- a/lib/Tmdb/Api/Tv.php +++ b/lib/Tmdb/Api/Tv.php @@ -12,8 +12,6 @@ */ namespace Tmdb\Api; -use Tmdb\Exception\NotImplementedException; - class Tv extends AbstractApi { @@ -22,11 +20,12 @@ class Tv * * @param $tvshow_id * @param array $options + * @param array $headers * @return mixed */ - public function getTvshow($tvshow_id, array $options = array()) + public function getTvshow($tvshow_id, array $options = array(), array $headers = array()) { - return $this->get('tv/' . $tvshow_id, $options); + return $this->get('tv/' . $tvshow_id, $options, $headers); } /** @@ -34,11 +33,12 @@ public function getTvshow($tvshow_id, array $options = array()) * * @param $tvshow_id * @param array $options + * @param array $headers * @return mixed */ - public function getCredits($tvshow_id, array $options = array()) + public function getCredits($tvshow_id, array $options = array(), array $headers = array()) { - return $this->get('tv/' . $tvshow_id . '/credits', $options); + return $this->get('tv/' . $tvshow_id . '/credits', $options, $headers); } /** @@ -46,11 +46,12 @@ public function getCredits($tvshow_id, array $options = array()) * * @param $tvshow_id * @param array $options + * @param array $headers * @return mixed */ - public function getCast($tvshow_id, array $options = array()) + public function getCast($tvshow_id, array $options = array(), array $headers = array()) { - return $this->get('tv/' . $tvshow_id . '/external_ids', $options); + return $this->get('tv/' . $tvshow_id . '/external_ids', $options, $headers); } /** @@ -58,10 +59,11 @@ public function getCast($tvshow_id, array $options = array()) * * @param $tvshow_id * @param array $options + * @param array $headers * @return mixed */ - public function getImages($tvshow_id, array $options = array()) + public function getImages($tvshow_id, array $options = array(), array $headers = array()) { - return $this->get('tv/' . $tvshow_id . '/images', $options); + return $this->get('tv/' . $tvshow_id . '/images', $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/TvEpisode.php b/lib/Tmdb/Api/TvEpisode.php index fe97c386..e419e5bc 100644 --- a/lib/Tmdb/Api/TvEpisode.php +++ b/lib/Tmdb/Api/TvEpisode.php @@ -24,11 +24,12 @@ class TvEpisode * @param $season_number * @param $episode_number * @param array $options + * @param array $headers * @return mixed */ - public function getEpisode($tvshow_id, $season_number, $episode_number, array $options = array()) + public function getEpisode($tvshow_id, $season_number, $episode_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s/episode/%s', $tvshow_id, $season_number,$episode_number), $options); + return $this->get(sprintf('tv/%s/season/%s/episode/%s', $tvshow_id, $season_number,$episode_number), $options, $headers); } /** @@ -38,11 +39,12 @@ public function getEpisode($tvshow_id, $season_number, $episode_number, array $o * @param $season_number * @param $episode_number * @param array $options + * @param array $headers * @return mixed */ - public function getEpisodeCredits($tvshow_id, $season_number, $episode_number, array $options = array()) + public function getEpisodeCredits($tvshow_id, $season_number, $episode_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s/episode/%s/credits', $tvshow_id, $season_number,$episode_number), $options); + return $this->get(sprintf('tv/%s/season/%s/episode/%s/credits', $tvshow_id, $season_number,$episode_number), $options, $headers); } /** @@ -52,11 +54,12 @@ public function getEpisodeCredits($tvshow_id, $season_number, $episode_number, a * @param $season_number * @param $episode_number * @param array $options + * @param array $headers * @return mixed */ - public function getEpisodeExternalIds($tvshow_id, $season_number, $episode_number, array $options = array()) + public function getEpisodeExternalIds($tvshow_id, $season_number, $episode_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s/episode/%s/external_ids', $tvshow_id, $season_number,$episode_number), $options); + return $this->get(sprintf('tv/%s/season/%s/episode/%s/external_ids', $tvshow_id, $season_number,$episode_number), $options, $headers); } /** @@ -66,10 +69,11 @@ public function getEpisodeExternalIds($tvshow_id, $season_number, $episode_numbe * @param $season_number * @param $episode_number * @param array $options + * @param array $headers * @return mixed */ - public function getEpisodeImages($tvshow_id, $season_number, $episode_number, array $options = array()) + public function getEpisodeImages($tvshow_id, $season_number, $episode_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s/episode/%s/images', $tvshow_id, $season_number,$episode_number), $options); + return $this->get(sprintf('tv/%s/season/%s/episode/%s/images', $tvshow_id, $season_number,$episode_number), $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Api/TvSeason.php b/lib/Tmdb/Api/TvSeason.php index db0943cd..527d5637 100644 --- a/lib/Tmdb/Api/TvSeason.php +++ b/lib/Tmdb/Api/TvSeason.php @@ -23,11 +23,12 @@ class TvSeason * @param $tvshow_id * @param $season_number * @param array $options + * @param array $headers * @return mixed */ - public function getSeason($tvshow_id, $season_number, array $options = array()) + public function getSeason($tvshow_id, $season_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $options); + return $this->get(sprintf('tv/%s/season/%s', $tvshow_id, $season_number), $options, $headers); } /** @@ -36,10 +37,11 @@ public function getSeason($tvshow_id, $season_number, array $options = array()) * @param $tvshow_id * @param $season_number * @param array $options + * @param array $headers * @return mixed */ - public function getSeasonExternalIds($tvshow_id, $season_number, array $options = array()) + public function getSeasonExternalIds($tvshow_id, $season_number, array $options = array(), array $headers = array()) { - return $this->get(sprintf('tv/%s/season/%s/external_ids', $tvshow_id, $season_number), $options); + return $this->get(sprintf('tv/%s/season/%s/external_ids', $tvshow_id, $season_number), $options, $headers); } } \ No newline at end of file diff --git a/lib/Tmdb/Client.php b/lib/Tmdb/Client.php index 879ddb0f..e9a86df4 100644 --- a/lib/Tmdb/Client.php +++ b/lib/Tmdb/Client.php @@ -14,9 +14,7 @@ use Guzzle\Http\Client as GuzzleClient; use Guzzle\Http\ClientInterface; -use Guzzle\Http\Message\RequestInterface; -use Tmdb\Api\ApiInterface; use Tmdb\Exception\InvalidArgumentException; use Tmdb\HttpClient\HttpClient; use Tmdb\HttpClient\HttpClientInterface; @@ -34,11 +32,15 @@ class Client { const TMDB_URI = 'http://api.themoviedb.org/3/'; /** + * Stores API authentication token + * * @var Token */ private $token; /** + * Stores the HTTP Client + * * @var HttpClientInterface */ private $httpClient; @@ -79,138 +81,148 @@ public function setToken(Token $token) return $this; } + /** + * @return Api\Configuration + */ + public function getConfigurationApi() + { + return new Api\Configuration($this); + } + + /** + * @return Api\Authentication + */ + public function getAuthenticationApi() + { + return new Api\Authentication($this); + } + + /** + * @return Api\Account + */ + public function getAccountApi() + { + return new Api\Account($this); + } + + /** + * @return Api\Collections + */ + public function getCollectionsApi() + { + return new Api\Collections($this); + } + /** * @return Api\Movies */ - public function getMovieApi() + public function getMoviesApi() { return new Api\Movies($this); } + /** + * @return Api\Tv + */ + public function getTvApi() + { + return new Api\Tv($this); + } + + /** + * @return Api\TvSeason + */ + public function getTvSeasonApi() + { + return new Api\TvSeason($this); + } + + /** + * @return Api\TvEpisode + */ + public function getTvEpisodeApi() + { + return new Api\TvEpisode($this); + } + /** * @return Api\People */ - public function getPersonApi() + public function getPeopleApi() { return new Api\People($this); } /** - * @return Api\Configuration + * @return Api\Lists */ - public function getConfigurationApi() + public function getListsApi() { - return new Api\Configuration($this); + return new Api\Lists($this); } + /** + * @return Api\Companies + */ + public function getCompaniesApi() + { + return new Api\Companies($this); + } /** - * Return the relevant API object - * - * @todo we should either register these by DI, or hardcode the return values through the constructor, and provide getApiConfiguration() type of methods - * - * @param $name - * @throws Exception\InvalidArgumentException - * @return ApiInterface + * @return Api\Genres */ - public function api($name) + public function getGenresApi() { - switch($name) { - case 'configuration': - /** @var Api\Configuration */ - $api = new Api\Configuration($this); - break; - - case 'authentication': - /** @var Api\Authentication */ - $api = new Api\Authentication($this); - break; - - case 'account': - /** @var Api\Account */ - $api = new Api\Account($this); - break; - - case 'movies': - /** @var Api\Movies */ - $api = new Api\Movies($this); - break; - - case 'collections': - /** @return Api\Collections */ - $api = new Api\Collections($this); - break; - - case 'tv': - /** @return Api\Tv */ - $api = new Api\Tv($this); - break; - - case 'tvseason': - /** @return Api\TvSeason */ - $api = new Api\TvSeason($this); - break; - - case 'tvepisode': - /** @return Api\TvEpisode */ - $api = new Api\TvEpisode($this); - break; - - case 'people': - /** @return Api\People */ - $api = new Api\People($this); - break; - - case 'lists': - /** @return Api\Lists */ - $api = new Api\Lists($this); - break; - - case 'companies': - /** @return Api\Companies */ - $api = new Api\Companies($this); - break; - - case 'genres': - /** @return Api\Genres */ - $api = new Api\Genres($this); - break; - - case 'keywords': - /** @return Api\Keywords */ - $api = new Api\Keywords($this); - break; - - case 'discover': - /** @return Api\Discover */ - $api = new Api\Discover($this); - break; - - case 'search': - /** @return Api\Search */ - $api = new Api\Search($this); - break; - - case 'reviews': - /** @return Api\Reviews */ - $api = new Api\Reviews($this); - break; - - case 'changes': - /** @return Api\Changes */ - $api = new Api\Changes($this); - break; - - case 'jobs': - /** @return Api\Jobs */ - $api = new Api\Jobs($this); - break; - - default: - throw new InvalidArgumentException(sprintf('The API type "%s" is not supported.', $name)); - } + return new Api\Genres($this); + } + + /** + * @return Api\Keywords + */ + public function getKeywordsApi() + { + return new Api\Keywords($this); + } - return $api; + /** + * @return Api\Discover + */ + public function getDiscoverApi() + { + return new Api\Discover($this); + } + + /** + * @return Api\Search + */ + public function getSearchApi() + { + return new Api\Search($this); + } + + /** + * @return Api\Reviews + */ + public function getReviewsApi() + { + return new Api\Reviews($this); + } + + /** + * @return Api\Changes + */ + public function getChangesApi() + { + return new Api\Changes($this); + } + + /** + * @return Api\Jobs + */ + public function getJobsApi() + { + return new Api\Jobs($this); } /** diff --git a/lib/Tmdb/Factory/ConfigurationFactory.php b/lib/Tmdb/Factory/ConfigurationFactory.php index d2e254ff..7cf37246 100644 --- a/lib/Tmdb/Factory/ConfigurationFactory.php +++ b/lib/Tmdb/Factory/ConfigurationFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Client; use Tmdb\Model\Common\Collection; use Tmdb\Model\Configuration; diff --git a/lib/Tmdb/Factory/GenreFactory.php b/lib/Tmdb/Factory/GenreFactory.php index 33b96075..69ff0101 100644 --- a/lib/Tmdb/Factory/GenreFactory.php +++ b/lib/Tmdb/Factory/GenreFactory.php @@ -12,7 +12,6 @@ */ namespace Tmdb\Factory; -use Tmdb\Client; use Tmdb\Model\Collection\Genres; use Tmdb\Model\Genre; @@ -39,19 +38,4 @@ public static function createCollection(array $data = array()) return $collection; } - - /** - * Load a genre with the given identifier - * - * @param Client $client - * @param $id - * @param $parameters - * @return $this - */ - public static function load(Client $client, $id, array $parameters = array()) { - $data = $client->api('genres')->getGenre($id, parent::parseQueryParameters($parameters)); - - return self::create($data); - } - -} \ No newline at end of file +} \ No newline at end of file diff --git a/lib/Tmdb/Factory/Common/ImageFactory.php b/lib/Tmdb/Factory/ImageFactory.php similarity index 94% rename from lib/Tmdb/Factory/Common/ImageFactory.php rename to lib/Tmdb/Factory/ImageFactory.php index 452846e4..44db57a6 100644 --- a/lib/Tmdb/Factory/Common/ImageFactory.php +++ b/lib/Tmdb/Factory/ImageFactory.php @@ -10,10 +10,9 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Factory\Common; +namespace Tmdb\Factory; -use Tmdb\Factory\AbstractFactory; -use Tmdb\Model\Common\Collection\Images; +use Tmdb\Model\Collection\Images; use Tmdb\Model\Image; class ImageFactory extends AbstractFactory diff --git a/lib/Tmdb/Factory/MovieFactory.php b/lib/Tmdb/Factory/MovieFactory.php index 01bbb0d5..a31bb229 100644 --- a/lib/Tmdb/Factory/MovieFactory.php +++ b/lib/Tmdb/Factory/MovieFactory.php @@ -12,9 +12,7 @@ */ namespace Tmdb\Factory; -use Tmdb\Client; use Tmdb\Factory\Common\GenericCollectionFactory; -use Tmdb\Factory\Common\ImageFactory; use Tmdb\Factory\People\CastFactory; use Tmdb\Factory\People\CrewFactory; use Tmdb\Model\Common\Collection; diff --git a/lib/Tmdb/Model/Helper/ImageHelper.php b/lib/Tmdb/Helper/ImageHelper.php similarity index 59% rename from lib/Tmdb/Model/Helper/ImageHelper.php rename to lib/Tmdb/Helper/ImageHelper.php index 605e8d88..313af778 100644 --- a/lib/Tmdb/Model/Helper/ImageHelper.php +++ b/lib/Tmdb/Helper/ImageHelper.php @@ -10,7 +10,7 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Helper; +namespace Tmdb\Helper; use Tmdb\Model\Configuration; use Tmdb\Model\Image; @@ -24,23 +24,42 @@ public function __construct(Configuration $config) $this->config = $config; } + /** + * Load the image configuration collection + * + * @return \Tmdb\Model\Common\Collection + */ public function getImageConfiguration() { return $this->config->getImages(); } + /** + * Get the url for the image resource + * + * @param Image $image + * @param string $size + * @return string + */ public function getUrl(Image $image, $size = 'original') { $config = $this->getImageConfiguration(); - return sprintf('%s%s%s', $config['base_url'] , $size, $image->getFilePath()); + return $config['base_url'] . $size . $image->getFilePath(); } + /** + * Get an img html tag for the image in the specified size + * + * @param Image $image + * @param string $size + * @return string + */ public function getHtml(Image $image, $size = 'original') { return sprintf( - '', + '', $this->getUrl($image, $size), - $image->getHeight(), - $image->getWidth() + $image->getWidth(), + $image->getHeight() ); } } \ No newline at end of file diff --git a/lib/Tmdb/Model/AbstractModel.php b/lib/Tmdb/Model/AbstractModel.php index 4f2eb7ec..c68b6b58 100644 --- a/lib/Tmdb/Model/AbstractModel.php +++ b/lib/Tmdb/Model/AbstractModel.php @@ -12,48 +12,11 @@ */ namespace Tmdb\Model; -use Tmdb\Client; - class AbstractModel { - public static $_properties; - - protected $_data = array(); - protected $_client = null; - - /** - * Retrieve the client - * - * @return Client - */ - public function getClient() - { - return $this->_client; - } - /** - * Set the client + * List of properties to populate by the ObjectHydrator * - * @param Client $client - * @return $this + * @var array */ - public function setClient(Client $client = null) - { - if (null !== $client) { - $this->_client = $client; - } - - return $this; - } - - /** - * Call a part of the API - * - * @param $api - * @return mixed - */ - public function api($api) - { - return $this->getClient()->api($api); - } - + public static $_properties = array(); } \ No newline at end of file diff --git a/lib/Tmdb/Model/Common/Collection/Images.php b/lib/Tmdb/Model/Collection/Images.php similarity index 96% rename from lib/Tmdb/Model/Common/Collection/Images.php rename to lib/Tmdb/Model/Collection/Images.php index d99d8c8b..b708b0ae 100644 --- a/lib/Tmdb/Model/Common/Collection/Images.php +++ b/lib/Tmdb/Model/Collection/Images.php @@ -10,7 +10,7 @@ * @copyright (c) 2013, Michael Roterman * @version 0.0.1 */ -namespace Tmdb\Model\Common\Collection; +namespace Tmdb\Model\Collection; use Tmdb\Model\Common\Collection; diff --git a/lib/Tmdb/Model/Image.php b/lib/Tmdb/Model/Image.php index df94a817..ac06ab8e 100644 --- a/lib/Tmdb/Model/Image.php +++ b/lib/Tmdb/Model/Image.php @@ -27,6 +27,8 @@ class Image extends AbstractModel { private $height; private $iso6391; private $aspectRatio; + private $voteAverage; + private $voteCount; protected $id; protected $type; @@ -36,7 +38,9 @@ class Image extends AbstractModel { 'width', 'height', 'iso_639_1', - 'aspect_ratio' + 'aspect_ratio', + 'vote_average', + 'vote_count' ); public static $_formats = array( @@ -47,35 +51,6 @@ class Image extends AbstractModel { 'stills' => self::FORMAT_STILL ); - /** - * Convert an array to an hydrated object - * - * @param Client $client - * @param array $data - * @return $this - */ - public static function fromArray(Client $client, array $data) - { - $image = new Image(); - //$image->setClient($client); - - return $image->hydrate($data); - } - - /** - * Load a person with the given identifier - * - * @param Client $client - * @param $id - * @param $with - * @return $this - */ - public static function load(Client $client, $id, array $with = array()) { - $data = $client->api('people')->getPerson($id, $with); - - return Person::fromArray($client, $data); - } - /** * Get the singular type as defined in $_types * @@ -84,8 +59,8 @@ public static function load(Client $client, $id, array $with = array()) { */ public static function getTypeFromCollectionName($name) { - if (array_key_exists($name, self::$_types)) { - return self::$_types[$name]; + if (array_key_exists($name, self::$_formats)) { + return self::$_formats[$name]; } } @@ -144,57 +119,57 @@ public function getHeight() } /** - * @param mixed $id + * @param mixed $iso6391 * @return $this */ - public function setId($id) + public function setIso6391($iso6391) { - $this->id = $id; + $this->iso6391 = $iso6391; return $this; } /** * @return mixed */ - public function getId() + public function getIso6391() { - return $this->id; + return $this->iso6391; } /** - * @param mixed $iso6391 + * @param mixed $voteAverage * @return $this */ - public function setIso6391($iso6391) + public function setVoteAverage($voteAverage) { - $this->iso6391 = $iso6391; + $this->voteAverage = $voteAverage; return $this; } /** * @return mixed */ - public function getIso6391() + public function getVoteAverage() { - return $this->iso6391; + return $this->voteAverage; } /** - * @param mixed $type + * @param mixed $voteCount * @return $this */ - public function setType($type) + public function setVoteCount($voteCount) { - $this->type = $type; + $this->voteCount = $voteCount; return $this; } /** * @return mixed */ - public function getType() + public function getVoteCount() { - return $this->type; + return $this->voteCount; } /** diff --git a/lib/Tmdb/Model/Movie.php b/lib/Tmdb/Model/Movie.php index 5b7dfcd7..68ee98b7 100644 --- a/lib/Tmdb/Model/Movie.php +++ b/lib/Tmdb/Model/Movie.php @@ -13,10 +13,10 @@ namespace Tmdb\Model; use Tmdb\Model\Common\Collection; -use Tmdb\Model\Common\Collection\Images; use Tmdb\Model\Collection\Credits; use Tmdb\Model\Collection\Genres; +use Tmdb\Model\Collection\Images; use Tmdb\Model\Collection\People; use Tmdb\Model\Common\Country; diff --git a/lib/Tmdb/Model/Person.php b/lib/Tmdb/Model/Person.php index ba70859a..cd0b5bef 100644 --- a/lib/Tmdb/Model/Person.php +++ b/lib/Tmdb/Model/Person.php @@ -65,39 +65,6 @@ public function __construct() $this->changes = new Collection(); } - /** - * Convert an array to an hydrated object - * - * @param Client $client - * @param array $data - * @return $this - */ - public static function fromArray(Client $client, array $data) - { - $person = new Person($data['id']); - //$person->setClient($client); - - if (array_key_exists('images', $data)) { - $data['images'] = parent::collectImages($client, $data['images']); - } - - return $person->hydrate($data); - } - - /** - * Load a person with the given identifier - * - * @param Client $client - * @param $id - * @param $parameters - * @return $this - */ - public static function load(Client $client, $id, array $parameters = array()) { - $data = $client->api('people')->getPerson($id, parent::parseQueryParameters($parameters)); - - return Person::fromArray($client, $data); - } - /** * @param mixed $adult * @return $this diff --git a/lib/Tmdb/Repository/AbstractRepository.php b/lib/Tmdb/Repository/AbstractRepository.php index 72346b9a..6222edb0 100644 --- a/lib/Tmdb/Repository/AbstractRepository.php +++ b/lib/Tmdb/Repository/AbstractRepository.php @@ -25,6 +25,9 @@ abstract class AbstractRepository { /** * Constructor * + * + * @todo create an interface for the client + * * @param Client $client */ public function __construct(Client $client) @@ -61,14 +64,25 @@ protected function parseQueryParameters(array $parameters = array()) return $parameters; } + /** + * @todo implement + * @param array $headers + * @return array + */ + protected function parseHeaders(array $headers = array()) + { + return $headers; + } + /** * Load the given identifier * * @param $id - * @param array $parameters + * @param array $parameters Query parameters to pass to the request + * @param array $headers Headers to pass to the request * @return mixed */ - abstract public function load($id, array $parameters = array()); + abstract public function load($id, array $parameters = array(), array $headers = array()); /** * Return the API Class diff --git a/lib/Tmdb/Repository/ConfigurationRepository.php b/lib/Tmdb/Repository/ConfigurationRepository.php index a00d0eb1..9494d152 100644 --- a/lib/Tmdb/Repository/ConfigurationRepository.php +++ b/lib/Tmdb/Repository/ConfigurationRepository.php @@ -21,10 +21,11 @@ class ConfigurationRepository extends AbstractRepository { * Load a movie with the given identifier * * @param $id - * @param $parameters + * @param array $parameters + * @param array $headers * @return Configuration */ - public function load($id = null, array $parameters = array()) { + public function load($id = null, array $parameters = array(), array $headers = array()) { $data = $this->getApi()->getConfiguration(); return ConfigurationFactory::create($data); @@ -38,7 +39,7 @@ public function load($id = null, array $parameters = array()) { * @param array $parameters * @return Configuration */ - public function refresh(array $parameters = array()) { + public function refresh(array $parameters = array(), array $headers = array()) { return $this->load(null, $parameters); } diff --git a/lib/Tmdb/Repository/GenreRepository.php b/lib/Tmdb/Repository/GenreRepository.php new file mode 100644 index 00000000..e69c0419 --- /dev/null +++ b/lib/Tmdb/Repository/GenreRepository.php @@ -0,0 +1,88 @@ + + * @copyright (c) 2013, Michael Roterman + * @version 0.0.1 + */ +namespace Tmdb\Repository; + +use Tmdb\Factory\GenreFactory; +use Tmdb\Model\Common\Collection; +use Tmdb\Model\Genre; + +class GenreRepository extends AbstractRepository { + /** + * Load a genre with the given identifier + * + * @param $id + * @param array $parameters + * @param array $headers + * @return Genre + */ + public function load($id, array $parameters = array(), array $headers = array()) { + $data = $this->getApi()->getGenre($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)); + + return GenreFactory::create($data); + } + + /** + * If you obtained an person model which is not completely hydrated, you can use this function. + * + * @param Genre $genre + * @param array $parameters + * @param array $headers + * @return Genre + */ + public function refresh(Genre $genre, array $parameters = array(), array $headers = array()) { + return $this->load($genre->getId(), $parameters, $headers); + } + + /** + * Get the list of genres. + * + * @param array $options + * @return Collection + */ + public function loadCollection(array $options = array()) + { + return $this->createCollection( + $this->getApi()->getGenres($options) + ); + } + + /** + * Create an collection of an array + * + * @param $data + * @return Collection + */ + private function createCollection($data){ + $collection = new Collection(); + + if (array_key_exists('genres', $data)) { + $data = $data['genres']; + } + + foreach($data as $item) { + $collection->add(null, GenreFactory::create($item)); + } + + return $collection; + } + + /** + * Return the related API class + * + * @return \Tmdb\Api\Genres + */ + public function getApi() + { + return $this->getClient()->getGenresApi(); + } +} \ No newline at end of file diff --git a/lib/Tmdb/Repository/MovieRepository.php b/lib/Tmdb/Repository/MovieRepository.php index c7dab6ad..f67a51e2 100644 --- a/lib/Tmdb/Repository/MovieRepository.php +++ b/lib/Tmdb/Repository/MovieRepository.php @@ -16,32 +16,42 @@ use Tmdb\Model\Common\Collection; use Tmdb\Model\Movie; +use \Tmdb\Model\Movie\QueryParameter\AppendToResponse; + class MovieRepository extends AbstractRepository { /** * Load a movie with the given identifier * + * If you want to optimize the result set/bandwidth you should define the AppendToResponse parameter + * * @param $id * @param $parameters + * @param $headers * @return Movie */ - public function load($id, array $parameters = array()) { + public function load($id, array $parameters = array(), array $headers = array()) + { - if (empty($parameters) && $parameters !== false) { - // Load a no-nonsense default set + if (empty($parameters)) { $parameters = array( - new \Tmdb\Model\Movie\QueryParameter\AppendToResponse(array( - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::CREDITS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::IMAGES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::KEYWORDS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::RELEASES, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRAILERS, - \Tmdb\Model\Movie\QueryParameter\AppendToResponse::TRANSLATIONS, + new AppendToResponse(array( + AppendToResponse::ALTERNATIVE_TITLES, + AppendToResponse::CHANGES, + AppendToResponse::CREDITS, + AppendToResponse::IMAGES, + AppendToResponse::KEYWORDS, + AppendToResponse::LISTS, + AppendToResponse::RELEASES, + AppendToResponse::REVIEWS, + AppendToResponse::SIMILAR_MOVIES, + AppendToResponse::TRAILERS, + AppendToResponse::TRANSLATIONS, )) ); } - $data = $this->getApi()->getMovie($id, $this->parseQueryParameters($parameters)); + $data = $this->getApi()->getMovie($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)); return MovieFactory::create($data); } @@ -53,10 +63,12 @@ public function load($id, array $parameters = array()) { * * @param Movie $movie * @param array $parameters + * @param array $headers * @return Movie */ - public function refresh(Movie $movie, array $parameters = array()) { - return $this->load($movie->getId(), $parameters); + public function refresh(Movie $movie, array $parameters = array(), array $headers = array()) + { + return $this->load($movie->getId(), $parameters, $headers); } /** @@ -66,7 +78,7 @@ public function refresh(Movie $movie, array $parameters = array()) { */ public function getApi() { - return $this->getClient()->getMovieApi(); + return $this->getClient()->getMoviesApi(); } /** diff --git a/lib/Tmdb/Repository/PersonRepository.php b/lib/Tmdb/Repository/PeopleRepository.php similarity index 59% rename from lib/Tmdb/Repository/PersonRepository.php rename to lib/Tmdb/Repository/PeopleRepository.php index 4423e545..c0251730 100644 --- a/lib/Tmdb/Repository/PersonRepository.php +++ b/lib/Tmdb/Repository/PeopleRepository.php @@ -15,26 +15,33 @@ use Tmdb\Factory\People\PeopleFactory; use Tmdb\Model\Person; -class PersonRepository extends AbstractRepository { +use Tmdb\Model\Person\QueryParameter\AppendToResponse; + +class PeopleRepository extends AbstractRepository { /** * Load a person with the given identifier * * @param $id - * @param $parameters + * @param array $parameters + * @param array $headers * @return Person */ - public function load($id, array $parameters = array()) { + public function load($id, array $parameters = array(), array $headers = array()) { if (empty($parameters) && $parameters !== false) { // Load a no-nonsense default set $parameters = array( - new \Tmdb\Model\Person\QueryParameter\AppendToResponse(array( - \Tmdb\Model\Person\QueryParameter\AppendToResponse::IMAGES, + new AppendToResponse(array( + AppendToResponse::IMAGES, + AppendToResponse::CHANGES, + AppendToResponse::COMBINED_CREDITS, + AppendToResponse::MOVIE_CREDITS, + AppendToResponse::TV_CREDITS, )) ); } - $data = $this->getApi()->getPerson($id, $this->parseQueryParameters($parameters)); + $data = $this->getApi()->getPerson($id, $this->parseQueryParameters($parameters), $this->parseHeaders($headers)); return PeopleFactory::create($data); } @@ -44,17 +51,20 @@ public function load($id, array $parameters = array()) { * * @param Person $person * @param array $parameters + * @param array $headers * @return Person */ - public function refresh(Person $person, array $parameters = array()) { - return $this->load($person->getId(), $parameters); + public function refresh(Person $person, array $parameters = array(), array $headers = array()) { + return $this->load($person->getId(), $parameters, $headers); } /** + * Return the related API class + * * @return \Tmdb\Api\People */ public function getApi() { - return $this->getClient()->getPersonApi(); + return $this->getClient()->getPeopleApi(); } } \ No newline at end of file