Exemple #1
0
 /**
  * @test
  */
 public function shouldAllowOverridingDefaultCollectionObjects()
 {
     $movie = new Movie();
     $class = new ResultCollection();
     $className = get_class($class);
     $movie->setChanges($class);
     $movie->setProductionCompanies($class);
     $movie->setProductionCountries($class);
     $movie->setSpokenLanguages($class);
     $movie->setCredits(new CreditsCollection());
     $movie->setLists($class);
     $movie->setVideos($class);
     $this->assertInstancesOf($movie, array('getChanges' => $className, 'getProductionCompanies' => $className, 'getProductionCountries' => $className, 'getSpokenLanguages' => $className, 'getCredits' => 'Tmdb\\Model\\Collection\\CreditsCollection', 'getLists' => $className, 'getVideos' => $className));
 }
 /**
  * @param  array $data
  * @return Movie
  */
 public function create(array $data = [])
 {
     if (!$data) {
         return null;
     }
     $movie = new Movie();
     if (array_key_exists('alternative_titles', $data) && array_key_exists('titles', $data['alternative_titles'])) {
         $movie->setAlternativeTitles($this->createGenericCollection($data['alternative_titles']['titles'], new Movie\AlternativeTitle()));
     }
     if (array_key_exists('credits', $data)) {
         if (array_key_exists('cast', $data['credits'])) {
             $movie->getCredits()->setCast($this->getCastFactory()->createCollection($data['credits']['cast']));
         }
         if (array_key_exists('crew', $data['credits'])) {
             $movie->getCredits()->setCrew($this->getCrewFactory()->createCollection($data['credits']['crew']));
         }
     }
     /** Genres */
     if (array_key_exists('genres', $data)) {
         $movie->setGenres($this->getGenreFactory()->createCollection($data['genres']));
     }
     /** Genres */
     if (array_key_exists('genre_ids', $data)) {
         $formattedData = [];
         foreach ($data['genre_ids'] as $genreId) {
             $formattedData[] = ['id' => $genreId];
         }
         $movie->setGenres($this->getGenreFactory()->createCollection($formattedData));
     }
     /** Images */
     if (array_key_exists('backdrop_path', $data)) {
         $movie->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path'));
     }
     if (array_key_exists('images', $data)) {
         $movie->setImages($this->getImageFactory()->createCollectionFromMovie($data['images']));
     }
     if (array_key_exists('poster_path', $data)) {
         $movie->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path'));
     }
     /** Keywords */
     if (array_key_exists('keywords', $data)) {
         $movie->setKeywords($this->getKeywordFactory()->createCollection($data['keywords']));
     }
     if (array_key_exists('releases', $data) && array_key_exists('countries', $data['releases'])) {
         $movie->setReleases($this->createGenericCollection($data['releases']['countries'], new Movie\Release()));
     }
     if (array_key_exists('videos', $data)) {
         $movie->setVideos($this->getVideoFactory()->createCollection($data['videos']));
     }
     if (array_key_exists('translations', $data) && array_key_exists('translations', $data['translations'])) {
         $movie->setTranslations($this->createGenericCollection($data['translations']['translations'], new Translation()));
     }
     if (array_key_exists('similar', $data)) {
         $movie->setSimilar($this->createResultCollection($data['similar']));
     }
     if (array_key_exists('reviews', $data)) {
         $movie->setReviews($this->getReviewFactory()->createResultCollection($data['reviews']));
     }
     if (array_key_exists('lists', $data)) {
         $movie->setLists($this->getListItemFactory()->createResultCollection($data['lists']));
     }
     if (array_key_exists('changes', $data)) {
         $movie->setChanges($this->getChangeFactory()->createCollection($data['changes']));
     }
     if (array_key_exists('production_companies', $data)) {
         $movie->setProductionCompanies($this->createGenericCollection($data['production_companies'], new Company()));
     }
     if (array_key_exists('production_countries', $data)) {
         $movie->setProductionCountries($this->createGenericCollection($data['production_countries'], new Country()));
     }
     if (array_key_exists('spoken_languages', $data)) {
         $movie->setSpokenLanguages($this->createGenericCollection($data['spoken_languages'], new SpokenLanguage()));
     }
     return $this->hydrate($movie, $data);
 }