Skip to content

Commit

Permalink
Adjusting credits dependency to latest API changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
wtfzdotnet committed Feb 3, 2014
1 parent 22e3716 commit 2d13dc5
Show file tree
Hide file tree
Showing 10 changed files with 332 additions and 39 deletions.
2 changes: 1 addition & 1 deletion lib/Tmdb/Common/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function hydrate(AbstractModel $object, $data = array())
* @param string $candidate
* @return string
*/
private function camelize($candidate)
public function camelize($candidate)
{
return lcfirst(
implode('',
Expand Down
95 changes: 93 additions & 2 deletions lib/Tmdb/Factory/PeopleFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
*/
namespace Tmdb\Factory;

use Tmdb\Common\ObjectHydrator;
use Tmdb\Factory\People\CastFactory;
use Tmdb\Factory\People\CrewFactory;
use Tmdb\Model\Collection\People\Cast;
use Tmdb\Model\Collection\People\Crew;
use Tmdb\Model\Common\GenericCollection;
use Tmdb\Model\Person\CastMember;
use Tmdb\Model\Person\CrewMember;
Expand All @@ -23,6 +28,16 @@ class PeopleFactory extends AbstractFactory {
*/
private $imageFactory;

/**
* @var People\CastFactory
*/
private $castFactory;

/**
* @var People\CrewFactory
*/
private $crewFactory;

/**
* Constructor
*/
Expand Down Expand Up @@ -59,15 +74,55 @@ public function create(array $data = array(), Person\AbstractMember $person = nu
$person->setProfile($this->getImageFactory()->createFromPath($data['profile_path'], 'profile_path'));
}

/** Credits */
if ($person instanceof Person) {
$this->applyCredits($data, $person);
}

return $this->hydrate($person, $data);
}

/**
* Apply credits
*
* @param array $data
* @param Person $person
*/
protected function applyCredits(array $data = array(), Person $person) {
$hydrator = new ObjectHydrator();
$types = array('movie_credits', 'tv_credits', 'combined_credits');

foreach($types as $type) {
if (array_key_exists($type, $data)) {
$method = $hydrator->camelize(sprintf('get_%s', $type));

if (array_key_exists('cast', $data[$type])) {
$person->$method()->setCast($this->createCollection(
$data[$type]['cast'],
new CastMember(),
new Cast())
);
}

if (array_key_exists('crew', $data[$type])) {
$person->$method()->setCrew($this->createCollection(
$data[$type]['crew'],
new CrewMember(),
new Crew())
);
}
}
}
}

/**
* {@inheritdoc}
*/
public function createCollection(array $data = array(), Person\AbstractMember $person = null)
public function createCollection(array $data = array(), Person\AbstractMember $person = null, $collection = null)
{
$collection = new GenericCollection();
if (!$collection) {
$collection = new GenericCollection();
}

if (array_key_exists('results', $data)) {
$data = $data['results'];
Expand All @@ -80,6 +135,42 @@ public function createCollection(array $data = array(), Person\AbstractMember $p
return $collection;
}

/**
* @param \Tmdb\Factory\People\CastFactory $castFactory
* @return $this
*/
public function setCastFactory($castFactory)
{
$this->castFactory = $castFactory;
return $this;
}

/**
* @return \Tmdb\Factory\People\CastFactory
*/
public function getCastFactory()
{
return $this->castFactory;
}

/**
* @param \Tmdb\Factory\People\CrewFactory $crewFactory
* @return $this
*/
public function setCrewFactory($crewFactory)
{
$this->crewFactory = $crewFactory;
return $this;
}

/**
* @return \Tmdb\Factory\People\CrewFactory
*/
public function getCrewFactory()
{
return $this->crewFactory;
}

/**
* @param \Tmdb\Factory\ImageFactory $imageFactory
* @return $this
Expand Down
4 changes: 2 additions & 2 deletions lib/Tmdb/Model/Collection/Changes.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* @copyright (c) 2013, Michael Roterman
* @version 0.0.1
*/
namespace Tmdb\Model\Common\Collection;
namespace Tmdb\Model\Collection;

use Tmdb\Model\Common\GenericCollection;

class Images extends GenericCollection {}
class Changes extends GenericCollection {}
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Collection/Credits/CombinedCredits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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\Model\Collection\Credits;

use Tmdb\Model\Collection\Credits;

class CombinedCredits extends Credits {}
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Collection/Credits/MovieCredits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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\Model\Collection\Credits;

use Tmdb\Model\Collection\Credits;

class MovieCredits extends Credits {}
17 changes: 17 additions & 0 deletions lib/Tmdb/Model/Collection/Credits/TvCredits.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?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\Model\Collection\Credits;

use Tmdb\Model\Collection\Credits;

class TvCredits extends Credits {}
Loading

0 comments on commit 2d13dc5

Please sign in to comment.