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.
Making a start of moving the ugly fromArray methods to dedicated Fact…
…ories
- Loading branch information
1 parent
3a07da7
commit 5c90abe
Showing
8 changed files
with
328 additions
and
230 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
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,50 @@ | ||
<?php | ||
/** | ||
* This file is part of the Wrike PHP API created by B-Found IM&S. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Wrike | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, B-Found Internet Marketing & Services | ||
* @version 0.0.1 | ||
*/ | ||
|
||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Model\Collection\Genres; | ||
use Tmdb\Model\Genre; | ||
|
||
class GenreFactory { | ||
/** | ||
* Convert an array to an hydrated object | ||
* | ||
* @param array $data | ||
* @return $this | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
$genre = new Genre(); | ||
|
||
return $genre->hydrate($data); | ||
} | ||
|
||
/** | ||
* Convert an array to an hydrated object | ||
* | ||
* @param array $data | ||
* @return Genre[] | ||
*/ | ||
public static function createCollection(array $data = array()) | ||
{ | ||
$collection = new Genres(); | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, self::create($item)); | ||
} | ||
|
||
return $collection; | ||
} | ||
|
||
} |
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,97 @@ | ||
<?php | ||
/** | ||
* This file is part of the Wrike PHP API created by B-Found IM&S. | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
* | ||
* @package Wrike | ||
* @author Michael Roterman <[email protected]> | ||
* @copyright (c) 2013, B-Found Internet Marketing & Services | ||
* @version 0.0.1 | ||
*/ | ||
|
||
namespace Tmdb\Factory; | ||
|
||
use Tmdb\Model\Movie; | ||
|
||
class MovieFactory { | ||
/** | ||
* Convert an array to an hydrated object | ||
* | ||
* @param array $data | ||
* @return $this | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
if (!$data) { | ||
return null; | ||
} | ||
|
||
$movie = new Movie($data['id']); | ||
|
||
// if (array_key_exists('alternative_titles', $data) && array_key_exists('titles', $data['alternative_titles'])) { | ||
// $movie->setAlternativeTitles(Movie::collectGenericCollection($client, $data['alternative_titles']['titles'], new AlternativeTitle())); | ||
// } | ||
// | ||
// $casts = array(); | ||
// $credits = $movie->getCredits(); | ||
// | ||
// /** Credits */ | ||
// if (array_key_exists('credits', $data)) { | ||
// $casts = $data['credits']; | ||
// } | ||
// | ||
// if (array_key_exists('casts', $data)) { | ||
// $casts = $data['casts']; | ||
// } | ||
// | ||
// if (array_key_exists('cast', $casts)) { | ||
// $credits->setCast(parent::collectCast($client, $casts['cast'])); | ||
// } | ||
// | ||
// if (array_key_exists('crew', $casts)) { | ||
// $credits->setCrew(parent::collectCrew($client, $casts['crew'])); | ||
// } | ||
// | ||
// $movie->setCredits($credits); | ||
// | ||
/** Genres */ | ||
if (array_key_exists('genres', $data)) { | ||
$movie->setGenres(GenreFactory::createCollection($data['genres'])); | ||
} | ||
// | ||
// /** Images */ | ||
// if (array_key_exists('images', $data)) { | ||
// $movie->setImages(parent::collectImages($client, $data['images'])); | ||
// } | ||
// | ||
// /** Keywords */ | ||
// if (array_key_exists('keywords', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('releases', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('trailers', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('translations', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('similar_movies', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('reviews', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('lists', $data)) { | ||
// } | ||
// | ||
// if (array_key_exists('changes', $data)) { | ||
// } | ||
|
||
return $movie->hydrate($data); | ||
} | ||
|
||
} |
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
Oops, something went wrong.