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.
Refactoring API, moving stuff up to factories
- Loading branch information
1 parent
5c90abe
commit d3dcb9e
Showing
8 changed files
with
215 additions
and
41 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,32 @@ | ||
<?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; | ||
|
||
abstract class AbstractFactory { | ||
/** | ||
* Convert an array to an hydrated object | ||
* | ||
* @param array $data | ||
* @return $this | ||
*/ | ||
abstract public static function create(array $data = array()); | ||
|
||
/** | ||
* Convert an array with an collection of items to an hydrated object collection | ||
* | ||
* @param array $data | ||
* @return $this | ||
*/ | ||
abstract public static function createCollection(array $data = array()); | ||
} |
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,45 @@ | ||
<?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\Movie; | ||
|
||
use Tmdb\Factory\AbstractFactory; | ||
use Tmdb\Model\Common\Collection; | ||
use Tmdb\Model\Movie\AlternativeTitle; | ||
|
||
class AlternativeTitleFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
$title = new AlternativeTitle(); | ||
|
||
return $title->hydrate($data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function createCollection(array $data = array()) | ||
{ | ||
$collection = new Collection(); | ||
|
||
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
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,45 @@ | ||
<?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\People; | ||
|
||
use Tmdb\Factory\AbstractFactory; | ||
use Tmdb\Model\Collection\People\Cast; | ||
use Tmdb\Model\Collection\People; | ||
|
||
class CastFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
$cast = new Cast(); | ||
|
||
return $cast->hydrate($data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function createCollection(array $data = array()) | ||
{ | ||
$collection = new People(); | ||
|
||
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,45 @@ | ||
<?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\People; | ||
|
||
use Tmdb\Factory\AbstractFactory; | ||
use Tmdb\Model\Collection\People\Crew; | ||
use Tmdb\Model\Collection\People; | ||
|
||
class CrewFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function create(array $data = array()) | ||
{ | ||
$crew = new Crew(); | ||
|
||
return $crew->hydrate($data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public static function createCollection(array $data = array()) | ||
{ | ||
$collection = new People(); | ||
|
||
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
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