vfalies / tmdb

PHP Wrapper for TMDB (The Movie DataBase) API V3
https://vfac.fr/projects/tmdb
MIT License
22 stars 5 forks source link

Items\Movie class methods don't return expected results #39

Closed maxdmyers closed 4 years ago

maxdmyers commented 4 years ago

Using the following code, I'm unable to retrieve results from TMdb.

$movie = [];
$tmdbMovieData = [];
$item = new Item($this->tmdb);
$tmdbMovieData  = $item->getMovie(11);
$movie['cast'] = $tmdbMovieData->getCast();
$movie['crew'] = $tmdbMovieData->getCrew();
$movie['trailers'] = $tmdbMovieData->getVideos();
var_dump($movie);

If I look at the constructor for Items\MovieVideos, I can see results being returned if I run var_dump($this->data->results);

This is related to #37. I'm not sure if I'm doing something incorrectly, or if there are a problem with these methods.

vfalies commented 4 years ago

Your code is correct, with it you can retrieve results without problems.

Be careful, methods like getCast(), getCrew() or getVideos() don't return an array or an object. They return a generator (https://www.php.net/manual/en/class.generator.php). To use it, you can used all methods available in that class or a foreach instruction (to get all elements).

In your case, if I use the code :

$movie = [];
$tmdbMovieData = [];
$item = new Item($tmdb);
$tmdbMovieData  = $item->getMovie(11);
$movie['cast'] = $tmdbMovieData->getCast();
$movie['crew'] = $tmdbMovieData->getCrew();
$movie['trailers'] = $tmdbMovieData->getVideos();

var_dump($movie);

You have the following return:

array (size=3)
  'cast' => 
    object(Generator)[47]
  'crew' => 
    object(Generator)[195]
  'trailers' => 
    object(Generator)[343]

If you use the current() method in your var_dump like:

var_dump($movie['trailers']->current());

You will have the following return

object(VfacTmdb\Results\Videos)[341]
  protected 'iso_639_1' => string 'en' (length=2)
  protected 'iso_3166_1' => string 'US' (length=2)
  protected 'key' => string 'vZ734NWnAHA' (length=11)
  protected 'name' => string 'Star Wars Episode IV: A New Hope - Trailer' (length=42)
  protected 'site' => string 'YouTube' (length=7)
  protected 'id' => null
  protected 'size' => int 1080
  protected 'type' => string 'Trailer' (length=7)
  protected 'property_blacklist' => 
    array (size=8)
      0 => string 'property_blacklist' (length=18)
      1 => string 'conf' (length=4)
      2 => string 'data' (length=4)
      3 => string 'logger' (length=6)
      4 => string 'tmdb' (length=4)
      5 => string 'params' (length=6)
      6 => string 'element_trait' (length=13)
      7 => string 'tvepisode_trait' (length=15)
  protected 'logger' => 
    object(Psr\Log\NullLogger)[5]
  protected 'conf' => 
    object(stdClass)[38]
      public 'images' => 
        object(stdClass)[21]
          public 'base_url' => string 'http://image.tmdb.org/t/p/' (length=26)
          public 'secure_base_url' => string 'https://image.tmdb.org/t/p/' (length=27)
          public 'backdrop_sizes' => 
            array (size=4)
              ...
          public 'logo_sizes' => 
            array (size=7)
              ...
          public 'poster_sizes' => 
            array (size=7)
              ...
          public 'profile_sizes' => 
            array (size=4)
              ...
          public 'still_sizes' => 
            array (size=4)
              ...
      public 'change_keys' => 
        array (size=53)
          0 => string 'adult' (length=5)
          1 => string 'air_date' (length=8)
          2 => string 'also_known_as' (length=13)
          3 => string 'alternative_titles' (length=18)
          4 => string 'biography' (length=9)
          5 => string 'birthday' (length=8)
          6 => string 'budget' (length=6)
          7 => string 'cast' (length=4)
          8 => string 'certifications' (length=14)
          9 => string 'character_names' (length=15)
          10 => string 'created_by' (length=10)
          11 => string 'crew' (length=4)
          12 => string 'deathday' (length=8)
          13 => string 'episode' (length=7)
          14 => string 'episode_number' (length=14)
          15 => string 'episode_run_time' (length=16)
          16 => string 'freebase_id' (length=11)
          17 => string 'freebase_mid' (length=12)
          18 => string 'general' (length=7)
          19 => string 'genres' (length=6)
          20 => string 'guest_stars' (length=11)
          21 => string 'homepage' (length=8)
          22 => string 'images' (length=6)
          23 => string 'imdb_id' (length=7)
          24 => string 'languages' (length=9)
          25 => string 'name' (length=4)
          26 => string 'network' (length=7)
          27 => string 'origin_country' (length=14)
          28 => string 'original_name' (length=13)
          29 => string 'original_title' (length=14)
          30 => string 'overview' (length=8)
          31 => string 'parts' (length=5)
          32 => string 'place_of_birth' (length=14)
          33 => string 'plot_keywords' (length=13)
          34 => string 'production_code' (length=15)
          35 => string 'production_companies' (length=20)
          36 => string 'production_countries' (length=20)
          37 => string 'releases' (length=8)
          38 => string 'revenue' (length=7)
          39 => string 'runtime' (length=7)
          40 => string 'season' (length=6)
          41 => string 'season_number' (length=13)
          42 => string 'season_regular' (length=14)
          43 => string 'spoken_languages' (length=16)
          44 => string 'status' (length=6)
          45 => string 'tagline' (length=7)
          46 => string 'title' (length=5)
          47 => string 'translations' (length=12)
          48 => string 'tvdb_id' (length=7)
          49 => string 'tvrage_id' (length=9)
          50 => string 'type' (length=4)
          51 => string 'video' (length=5)
          52 => string 'videos' (length=6)
  protected 'tmdb' => 
    object(VfacTmdb\Tmdb)[2]
      private 'api_key' => string '62dfe9839b8937e595e325a4144702ad' (length=32)
      protected 'configuration' => 
        object(stdClass)[38]
          public 'images' => 
            object(stdClass)[21]
              ...
          public 'change_keys' => 
            array (size=53)
              ...
      protected 'genres' => null
      public 'base_api_url' => string 'https://api.themoviedb.org/' (length=27)
      protected 'logger' => 
        object(Psr\Log\NullLogger)[5]
      protected 'version' => int 3
      protected 'http_request' => 
        object(VfacTmdb\lib\Guzzle\Client)[6]
          protected 'guzzleClient' => 
            object(GuzzleHttp\Client)[7]
              ...
      protected 'request' => 
        object(stdClass)[20]
      protected 'url' => string 'https://api.themoviedb.org/3/movie/11/videos?api_key=62dfe9839b8937e595e325a4144702ad' (length=85)
  protected 'data' => 
    object(stdClass)[346]
      public 'id' => string '533ec651c3a368544800000a' (length=24)
      public 'iso_639_1' => string 'en' (length=2)
      public 'iso_3166_1' => string 'US' (length=2)
      public 'key' => string 'vZ734NWnAHA' (length=11)
      public 'name' => string 'Star Wars Episode IV: A New Hope - Trailer' (length=42)
      public 'site' => string 'YouTube' (length=7)
      public 'size' => int 1080
      public 'type' => string 'Trailer' (length=7)
  public 'video_id' => string '533ec651c3a368544800000a' (length=24)
maxdmyers commented 4 years ago

My apologies! I was unfamiliar with the Generator class. I will try again. Thank you, again, for your work on this!