Skip to content

Commit

Permalink
Merge pull request #8 from vfalies/refactoring_get
Browse files Browse the repository at this point in the history
Refactoring get
  • Loading branch information
vfalies committed Jun 2, 2017
2 parents 7ac3f42 + f11fcef commit 67aa47b
Show file tree
Hide file tree
Showing 20 changed files with 258 additions and 128 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,17 @@ $tmdb = new Tmdb('your_api_key');
$search = new Search($tmdb);
$responses = $search->movie('star wars');

// Get title of the first result in API response
echo $search->getMovie($responses->current()->id)->getTitle();

// Get all results
foreach ($responses as $response)
{
echo $search->getMovie($response->id)->getTitle();
}

// Get movie information
$item = new Item($tmdb);
$infos = $item->getMovie(11, array('language' => 'fr-FR');

echo $infos->getTitle();
```

## Documentation
Expand Down
42 changes: 42 additions & 0 deletions src/Catalog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace vfalies\tmdb;

use vfalies\tmdb\Catalogs\Genres;

class Catalog
{

private $tmdb = null;

/**
* Constructor
* @param \vfalies\tmdb\Tmdb $tmdb
*/
public function __construct(Tmdb $tmdb)
{
$this->tmdb = $tmdb;
}

/**
* Get movie genres list
* @param array $options
* @return \Generator
*/
public function getMovieGenres(array $options = array()): \Generator
{
$catalog = new Genres($this->tmdb);
return $catalog->getMovieList($options);
}

/**
* Get TVShow genres list
* @param array $options
* @return \Generator
*/
public function getTVShowGenres(array $options = array()): \Generator
{
$catalog = new Genres($this->tmdb);
return $catalog->getTVList($options);
}
}
8 changes: 6 additions & 2 deletions src/Genres.php → src/Catalogs/Genres.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<?php

namespace vfalies\tmdb;
namespace vfalies\tmdb\Catalogs;

class Genres implements Interfaces\GenresInterface
use vfalies\tmdb\Interfaces\GenresInterface;
use vfalies\tmdb\Tmdb;
use vfalies\tmdb\lib\CurlRequest;

class Genres implements GenresInterface
{

protected $tmdb = null;
Expand Down
63 changes: 63 additions & 0 deletions src/Item.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

namespace vfalies\tmdb;

use vfalies\tmdb\Items\Movie;
use vfalies\tmdb\Items\Collection;
use vfalies\tmdb\Items\TVShow;

class Item
{
private $tmdb = null;

/**
* Constructor
* @param \vfalies\tmdb\Tmdb $tmdb
*/

public function __construct(Tmdb $tmdb)
{
$this->tmdb = $tmdb;
}

/**
* Get movie details
* @param int $movie_id
* @param array $options
* @return \vfalies\tmdb\Items\Movie
*/
public function getMovie(int $movie_id, array $options = array()): Movie
{
$movie = new Movie($this->tmdb, $movie_id, $options);

return $movie;
}

/**
* Get collection details
* @param int $collection_id
* @param array $options
* @return \vfalies\tmdb\Items\Collection
*/
public function getCollection(int $collection_id, array $options = array()): Collection
{
$collection = new Collection($this->tmdb, $collection_id, $options);

return $collection;
}

/**
* Get TV Show details
* @param int $tv_id
* @param array $options
* @return \vfalies\tmdb\Items\TVShow
*/
public function getTVShow(int $tv_id, array $options = array()): TVShow
{
$tv = new TVShow($this->tmdb, $tv_id, $options);

return $tv;
}


}
14 changes: 9 additions & 5 deletions src/Items/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace vfalies\tmdb\Items;

class Collection extends Item implements \vfalies\tmdb\Interfaces\CollectionInterface
use vfalies\tmdb\Interfaces\CollectionInterface;
use vfalies\tmdb\Tmdb;

class Collection extends Item implements CollectionInterface
{

// Private loaded data
Expand All @@ -13,10 +16,11 @@ class Collection extends Item implements \vfalies\tmdb\Interfaces\CollectionInte

/**
* Constructor
* @param \vfalies\tmdb\Tmdb $tmdb
* @throws \Exception
* @param Tmdb $tmdb
* @param int $collection_id
* @param array $options
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, $collection_id, array $options = array())
public function __construct(Tmdb $tmdb, int $collection_id, array $options = array())
{
parent::__construct($tmdb, $collection_id, $options, 'collection');
}
Expand Down Expand Up @@ -47,7 +51,7 @@ public function getName(): string

/**
* Get collection parts
* @return Generator|SearchMovieResult
* @return Generator
*/
public function getParts(): \Generator
{
Expand Down
7 changes: 5 additions & 2 deletions src/Items/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace vfalies\tmdb\Items;

use vfalies\tmdb\Tmdb;
use vfalies\tmdb\lib\CurlRequest;

abstract class Item
{
protected $data = null;
Expand All @@ -17,15 +20,15 @@ abstract class Item
* @param string $item_name
* @throws \Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $options, string $item_name)
public function __construct(Tmdb $tmdb, int $item_id, array $options, string $item_name)
{
try
{
$this->id = (int) $item_id;
$this->tmdb = $tmdb;
$this->conf = $this->tmdb->getConfiguration();
$params = $this->tmdb->checkOptions($options);
$this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params);
$this->data = $this->tmdb->sendRequest(new CurlRequest(), $item_name . '/'.(int) $item_id, null, $params);
}
catch (\Exception $ex)
{
Expand Down
7 changes: 5 additions & 2 deletions src/Items/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace vfalies\tmdb\Items;

class Movie extends Item implements \vfalies\tmdb\Interfaces\MovieInterface
use vfalies\tmdb\Interfaces\MovieInterface;
use vfalies\tmdb\Tmdb;

class Movie extends Item implements MovieInterface
{
/**
* Constructor
Expand All @@ -11,7 +14,7 @@ class Movie extends Item implements \vfalies\tmdb\Interfaces\MovieInterface
* @param array $options
* @throws Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $movie_id, array $options = array())
public function __construct(Tmdb $tmdb, int $movie_id, array $options = array())
{
parent::__construct($tmdb, $movie_id, $options, 'movie');
}
Expand Down
7 changes: 5 additions & 2 deletions src/Items/TVShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

namespace vfalies\tmdb\Items;

class TVShow extends Item implements \vfalies\tmdb\Interfaces\TVShowInterface
use vfalies\tmdb\Interfaces\TVShowInterface;
use vfalies\tmdb\Tmdb;

class TVShow extends Item implements TVShowInterface
{

public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $tv_id, array $options = array())
public function __construct(Tmdb $tmdb, int $tv_id, array $options = array())
{
parent::__construct($tmdb, $tv_id, $options, 'tv');
}
Expand Down
4 changes: 3 additions & 1 deletion src/Results/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace vfalies\tmdb\Results;

use vfalies\tmdb\Tmdb;

class Collection extends Results
{

Expand All @@ -13,7 +15,7 @@ class Collection extends Results
* @param \stdClass $result
* @throws \Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result)
public function __construct(Tmdb $tmdb, \stdClass $result)
{
parent::__construct($tmdb, $result);

Expand Down
4 changes: 3 additions & 1 deletion src/Results/Movie.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace vfalies\tmdb\Results;

use vfalies\tmdb\Tmdb;

class Movie extends Results
{
protected $overview = null;
Expand All @@ -15,7 +17,7 @@ class Movie extends Results
* @param \stdClass $result
* @throws \Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result)
public function __construct(Tmdb $tmdb, \stdClass $result)
{
parent::__construct($tmdb, $result);

Expand Down
3 changes: 2 additions & 1 deletion src/Results/Results.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace vfalies\tmdb\Results;
use vfalies\tmdb\Tmdb;

abstract class Results implements \vfalies\tmdb\Interfaces\ResultsInterface
{
Expand All @@ -16,7 +17,7 @@ abstract class Results implements \vfalies\tmdb\Interfaces\ResultsInterface
* @param \stdClass $result
* @throws \Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result)
public function __construct(Tmdb $tmdb, \stdClass $result)
{
// Valid input object
$properties = get_object_vars($this);
Expand Down
4 changes: 3 additions & 1 deletion src/Results/TVShow.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace vfalies\tmdb\Results;

use vfalies\tmdb\Tmdb;

class TVShow extends Results
{

Expand All @@ -16,7 +18,7 @@ class TVShow extends Results
* @param \stdClass $result
* @throws \Exception
*/
public function __construct(\vfalies\tmdb\Tmdb $tmdb, \stdClass $result)
public function __construct(Tmdb $tmdb, \stdClass $result)
{
parent::__construct($tmdb, $result);

Expand Down
41 changes: 2 additions & 39 deletions src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace vfalies\tmdb;

use vfalies\tmdb\lib\CurlRequest;

class Search
{

Expand Down Expand Up @@ -124,45 +126,6 @@ public function searchCollection(string $query, array $options = array()): \Gene
}
}

/**
* Get movie details
* @param int $movie_id
* @param array $options
* @return \vfalies\tmdb\Items\Movie
*/
public function getMovie(int $movie_id, array $options = array()): Items\Movie
{
$movie = new Items\Movie($this->tmdb, $movie_id, $options);

return $movie;
}

/**
* Get collection details
* @param int $collection_id
* @param array $options
* @return \vfalies\tmdb\Items\Collection
*/
public function getCollection(int $collection_id, array $options = array()): Items\Collection
{
$collection = new Items\Collection($this->tmdb, $collection_id, $options);

return $collection;
}

/**
* Get TV Show details
* @param int $tv_id
* @param array $options
* @return \vfalies\tmdb\Items\TVShow
*/
public function getTVShow(int $tv_id, array $options = array()): Items\TVShow
{
$tv = new Items\TVShow($this->tmdb, $tv_id, $options);

return $tv;
}

/**
* Get page from result search
* @return int
Expand Down
Loading

0 comments on commit 67aa47b

Please sign in to comment.