Skip to content

Commit

Permalink
Adding the implementation of Collection, this caused some disturbance…
Browse files Browse the repository at this point in the history
… and decided to rename the generic collection object to GenericCollection to avoid confusion with the Collection api method
  • Loading branch information
wtfzdotnet committed Jan 18, 2014
1 parent 5d31af3 commit 3a6ce54
Show file tree
Hide file tree
Showing 40 changed files with 568 additions and 142 deletions.
22 changes: 22 additions & 0 deletions examples/collection/model/all.php
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 <[email protected]>
* @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\CollectionRepository($client);
$collection = $repository->load(10);

var_dump($collection);
2 changes: 1 addition & 1 deletion examples/people/model/all.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
$token = new \Tmdb\ApiToken(TMDB_API_KEY);
$client = new \Tmdb\Client($token);

$repository = new \Tmdb\Repository\PersonRepository($client);
$repository = new \Tmdb\Repository\PeopleRepository($client);
$person = $repository->load(33);

var_dump($person);
59 changes: 59 additions & 0 deletions lib/Tmdb/Factory/CollectionFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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 <[email protected]>
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Factory;

class CollectionFactory extends AbstractFactory
{
/**
* {@inheritdoc}
* @return \Tmdb\Model\Collection
*/
public static function create(array $data = array())
{
$collection = new \Tmdb\Model\Collection();

if (array_key_exists('parts', $data)) {
$collection->setParts(
MovieFactory::createCollection($data['parts'])
);
}

if (array_key_exists('backdrop_path', $data)) {
$collection->setBackdrop(ImageFactory::createFromPath($data['backdrop_path'], 'backdrop_path'));
}

if (array_key_exists('images', $data)) {
$collection->setImages(ImageFactory::createCollectionFromMovie($data['images']));
}

if (array_key_exists('poster_path', $data)) {
$collection->setPoster(ImageFactory::createFromPath($data['poster_path'], 'poster_path'));
}

return parent::hydrate($collection, $data);
}

/**
* {@inheritdoc}
*/
public static function createCollection(array $data = array())
{
$collection = new \Tmdb\Model\Common\Collection();

foreach($data as $item) {
$collection->add(null, self::create($item));
}

return $collection;
}
}
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/Common/GenericCollectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Factory\Common;

use Tmdb\Common\ObjectHydrator;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;

class GenericCollectionFactory {
/**
Expand All @@ -33,7 +33,7 @@ public static function createCollection(array $data = array(), $class)
$class = get_class($class);
}

$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, ObjectHydrator::hydrate(new $class(), $item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/CompanyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
namespace Tmdb\Factory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Company;

class CompanyFactory extends AbstractFactory
Expand All @@ -30,7 +30,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/ConfigurationFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
namespace Tmdb\Factory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Configuration;

class ConfigurationFactory extends AbstractFactory
Expand All @@ -32,7 +32,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/Movie/AlternativeTitleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Factory\Movie;

use Tmdb\Factory\AbstractFactory;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Movie\AlternativeTitle;

class AlternativeTitleFactory extends AbstractFactory
Expand All @@ -33,7 +33,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/MovieFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Tmdb\Factory\Common\GenericCollectionFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Common\Trailer\Youtube;
use Tmdb\Model\Common\Translation;
use Tmdb\Model\Movie;
Expand Down Expand Up @@ -107,7 +107,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/People/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Tmdb\Factory\AbstractFactory;
use Tmdb\Factory\ImageFactory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
use Tmdb\Model\Person;
Expand Down Expand Up @@ -57,7 +57,7 @@ public static function create(array $data = array(), Person\AbstractMember $pers
*/
public static function createCollection(array $data = array(), Person\AbstractMember $person = null)
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item, $person));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/TvEpisodeFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Tmdb\Factory\Common\GenericCollectionFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;

use Tmdb\Model\Tv\ExternalIds;
use Tmdb\Model\Tv\Person\CastMember;
Expand Down Expand Up @@ -64,7 +64,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/TvFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;

use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;

use Tmdb\Model\Common\Translation;
use Tmdb\Model\Tv\ExternalIds;
Expand Down Expand Up @@ -84,7 +84,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Factory/TvSeasonFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
use Tmdb\Factory\Common\GenericCollectionFactory;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;

use Tmdb\Model\Tv\Episode;
use Tmdb\Model\Tv\ExternalIds;
Expand Down Expand Up @@ -70,7 +70,7 @@ public static function create(array $data = array())
*/
public static function createCollection(array $data = array())
{
$collection = new Collection();
$collection = new GenericCollection();

foreach($data as $item) {
$collection->add(null, self::create($item));
Expand Down
6 changes: 3 additions & 3 deletions lib/Tmdb/Model/Changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
namespace Tmdb\Model;

use Tmdb\Model\Changes\Change;
use Tmdb\Model\Common\Collection;
use Tmdb\Model\Common\GenericCollection;

class Changes extends AbstractModel {

Expand Down Expand Up @@ -62,11 +62,11 @@ public function page($page = 1) {
/**
* Execute the current state
*
* @return Collection
* @return GenericCollection
*/
public function execute()
{
$collection = new Collection();
$collection = new GenericCollection();

$response = $this->getClient()->api('changes')->getMovieChanges(array(
'from' => $this->from,
Expand Down
Loading

0 comments on commit 3a6ce54

Please sign in to comment.