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 Movie to actually contain the correct model of changes
- Loading branch information
1 parent
04ecef8
commit d4e5d7d
Showing
6 changed files
with
303 additions
and
9 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,71 @@ | ||
<?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\Common; | ||
|
||
use Tmdb\Factory\AbstractFactory; | ||
use Tmdb\Model\Common\Change; | ||
use Tmdb\Model\Common\GenericCollection; | ||
|
||
class ChangeFactory extends AbstractFactory | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function create(array $data = array()) | ||
{ | ||
$change = new Change(); | ||
|
||
if (array_key_exists('items', $data)) { | ||
$items = new GenericCollection(); | ||
|
||
foreach($data['items'] as $item) { | ||
$item = $this->createChangeItem($item); | ||
|
||
$items->add(null, $item); | ||
} | ||
|
||
$change->setItems($items); | ||
} | ||
|
||
return $this->hydrate($change, $data); | ||
} | ||
|
||
/** | ||
* Create individual change items | ||
* | ||
* @param array $data | ||
* @return \Tmdb\Model\AbstractModel | ||
*/ | ||
private function createChangeItem(array $data = array()) | ||
{ | ||
return $this->hydrate(new Change\Item(), $data); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function createCollection(array $data = array()) | ||
{ | ||
$collection = new GenericCollection(); | ||
|
||
if (array_key_exists('changes', $data)) { | ||
$data = $data['changes']; | ||
} | ||
|
||
foreach($data as $item) { | ||
$collection->add(null, $this->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,75 @@ | ||
<?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\Common; | ||
|
||
use Tmdb\Model\AbstractModel; | ||
|
||
class Change extends AbstractModel { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $key; | ||
|
||
/** | ||
* @var GenericCollection | ||
*/ | ||
private $items; | ||
|
||
public static $_properties = array( | ||
'key', | ||
); | ||
|
||
public function __construct() | ||
{ | ||
$this->items = new GenericCollection(); | ||
} | ||
|
||
/** | ||
* @param \Tmdb\Model\Common\GenericCollection $items | ||
* @return $this | ||
*/ | ||
public function setItems($items) | ||
{ | ||
$this->items = $items; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \Tmdb\Model\Common\GenericCollection | ||
*/ | ||
public function getItems() | ||
{ | ||
return $this->items; | ||
} | ||
|
||
/** | ||
* @param string $key | ||
* @return $this | ||
*/ | ||
public function setKey($key) | ||
{ | ||
$this->key = $key; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getKey() | ||
{ | ||
return $this->key; | ||
} | ||
|
||
|
||
} |
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,124 @@ | ||
<?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\Common\Change; | ||
|
||
use Tmdb\Model\AbstractModel; | ||
|
||
class Item extends AbstractModel { | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $action; | ||
|
||
/** | ||
* @var \DateTime | ||
*/ | ||
private $time; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
private $value; | ||
|
||
public static $_properties = array( | ||
'id', | ||
'action', | ||
'time', | ||
'value' | ||
); | ||
|
||
/** | ||
* @param string $action | ||
* @return $this | ||
*/ | ||
public function setAction($action) | ||
{ | ||
$this->action = $action; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAction() | ||
{ | ||
return $this->action; | ||
} | ||
|
||
/** | ||
* @param string $id | ||
* @return $this | ||
*/ | ||
public function setId($id) | ||
{ | ||
$this->id = $id; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
/** | ||
* @param string|\DateTime $time | ||
* @return $this | ||
*/ | ||
public function setTime($time) | ||
{ | ||
if (!$time instanceof \DateTime) { | ||
$time = new \DateTime($time); | ||
} | ||
|
||
$this->time = $time; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return \DateTime | ||
*/ | ||
public function getTime() | ||
{ | ||
return $this->time; | ||
} | ||
|
||
/** | ||
* @param array $value | ||
* @return $this | ||
*/ | ||
public function setValue($value) | ||
{ | ||
$this->value = $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getValue() | ||
{ | ||
return $this->value; | ||
} | ||
|
||
|
||
|
||
} |