forked from php-tmdb/api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
632c8bf
commit 37cb54f
Showing
10 changed files
with
933 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <michael@wtfz.net> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$repository = new \Tmdb\Repository\ListRepository($client); | ||
$list = $repository->load('509ec17b19c2950a0600050d'); | ||
|
||
var_dump($list); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <michael@wtfz.net> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
require_once('../../../vendor/autoload.php'); | ||
require_once('../../../apikey.php'); | ||
|
||
$token = new \Tmdb\ApiToken(TMDB_API_KEY); | ||
$client = new \Tmdb\Client($token); | ||
|
||
$repository = new \Tmdb\Repository\ListRepository($client); | ||
$list = $repository->getItemStatus('509ec17b19c2950a0600050d'); | ||
|
||
var_dump($list); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <michael@wtfz.net> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Factory\Lists\ListItemFactory; | ||
use Tmdb\Model\Collection\Genres; | ||
use Tmdb\Model\Genre; | ||
use Tmdb\Model\Lists; | ||
use Tmdb\Model\Movie; | ||
|
||
class ListFactory extends AbstractFactory | ||
{ | ||
/** | ||
* @var ImageFactory | ||
*/ | ||
private $imageFactory; | ||
|
||
/** | ||
* @var ListItemFactory | ||
*/ | ||
private $listItemFactory; | ||
|
||
public function __construct() | ||
{ | ||
$this->imageFactory = new ImageFactory(); | ||
$this->listItemFactory = new ListItemFactory(); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return Genre | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
$lists = new Lists(); | ||
|
||
if (array_key_exists('items', $data)) { | ||
$lists->setItems( | ||
$this->getListItemFactory()->createCollection($data['items']) | ||
); | ||
} | ||
|
||
/** Images */ | ||
if (array_key_exists('backdrop_path', $data)) { | ||
$lists->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); | ||
} | ||
|
||
if (array_key_exists('poster_path', $data)) { | ||
$lists->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); | ||
} | ||
return $this->hydrate($lists, $data); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return Movie | ||
*/ | ||
public function createItemStatus(array $data = array()) | ||
{ | ||
return $this->hydrate(new Lists\ItemStatus(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new Genres(); | ||
|
||
if (array_key_exists('genres', $data)) { | ||
$data = $data['genres']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->addGenre($this->create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Factory\ImageFactory $imageFactory | ||
* @return $this | ||
*/ | ||
public function setImageFactory($imageFactory) | ||
{ | ||
$this->imageFactory = $imageFactory; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Factory\ImageFactory | ||
*/ | ||
public function getImageFactory() | ||
{ | ||
return $this->imageFactory; | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Factory\Lists\ListItemFactory $listItemFactory | ||
* @return $this | ||
*/ | ||
public function setListItemFactory($listItemFactory) | ||
{ | ||
$this->listItemFactory = $listItemFactory; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Factory\Lists\ListItemFactory | ||
*/ | ||
public function getListItemFactory() | ||
{ | ||
return $this->listItemFactory; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
<?php | ||
/** | ||
* This file is part of the Tmdb PHP API created by Michael Roterman. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Tmdb | ||
* @author Michael Roterman <michael@wtfz.net> | ||
* @copyright (c) 2013, Michael Roterman | ||
* @version 0.0.1 | ||
*/ | ||
namespace Tmdb\Factory\Lists; | ||
|
||
use Tmdb\Factory\AbstractFactory; | ||
use Tmdb\Factory\ImageFactory; | ||
use Tmdb\Model\Common\GenericCollection; | ||
use Tmdb\Model\Lists\ListItem; | ||
|
||
class ListItemFactory extends AbstractFactory | ||
{ | ||
/** | ||
* @var ImageFactory | ||
*/ | ||
private $imageFactory; | ||
|
||
public function __construct() | ||
{ | ||
$this->imageFactory = new ImageFactory(); | ||
} | ||
|
||
/** | ||
* @param array $data | ||
* | ||
* @return ListItem | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
$listItem = new ListItem(); | ||
|
||
/** Images */ | ||
if (array_key_exists('backdrop_path', $data)) { | ||
$listItem->setBackdropImage($this->getImageFactory()->createFromPath($data['backdrop_path'], 'backdrop_path')); | ||
} | ||
|
||
if (array_key_exists('poster_path', $data)) { | ||
$listItem->setPosterImage($this->getImageFactory()->createFromPath($data['poster_path'], 'poster_path')); | ||
} | ||
|
||
return $this->hydrate($listItem, $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new GenericCollection(); | ||
|
||
if (array_key_exists('items', $data)) { | ||
$data = $data['items']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, $this->create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Factory\ImageFactory $imageFactory | ||
* @return $this | ||
*/ | ||
public function setImageFactory($imageFactory) | ||
{ | ||
$this->imageFactory = $imageFactory; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Factory\ImageFactory | ||
*/ | ||
public function getImageFactory() | ||
{ | ||
return $this->imageFactory; | ||
} | ||
} |
Oops, something went wrong.