/** * @param array $data * @return Movie */ public function create(array $data = array()) { 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'])); } /** 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())); } /** * @TODO actually implement more providers? * ( Can't seem to find any quicktime related trailers anyways? ). For now KISS */ if (array_key_exists('trailers', $data) && array_key_exists('youtube', $data['trailers'])) { $movie->setTrailers($this->createGenericCollection($data['trailers']['youtube'], new Youtube())); } 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_movies', $data)) { $movie->setSimilarMovies($this->createResultCollection($data['similar_movies'])); } 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())); } return $this->hydrate($movie, $data); }