Skip to content

Commit

Permalink
Implement JsonSerializable
Browse files Browse the repository at this point in the history
  • Loading branch information
webeweb committed Jan 24, 2020
1 parent dad5716 commit 313cea0
Show file tree
Hide file tree
Showing 75 changed files with 1,125 additions and 38 deletions.
9 changes: 9 additions & 0 deletions src/Model/AbstractCredit.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,13 @@
abstract class AbstractCredit extends AbstractModel {

use StringContentTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
];
}
}
38 changes: 36 additions & 2 deletions src/Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,53 @@

namespace WBW\Library\XMLTV\Model;

use JsonSerializable;

/**
* Abstract node.
* Abstract model.
*
* @author webeweb <https://github.com/webeweb/>
* @package WBW\Library\XMLTV\Model
* @abstract
*/
abstract class AbstractModel {
abstract class AbstractModel implements JsonSerializable {

/**
* Constructor.
*/
public function __construct() {
// NOTHING TO DO.
}

/**
* Serialize an array.
*
* @param AbstractModel[] $models The models.
* @return array Returns the serialized array.
*/
public static function serializeArray(array $models) {

$output = [];

foreach ($models as $current) {
$output[] = static::serializeModel($current);
}

return $output;
}

/**
* Serialize a model.
*
* @param AbstractModel|null $model The model.
* @return array Returns the serialized model.
*/
public static function serializeModel(AbstractModel $model = null) {

if (null === $model) {
return null;
}

return $model->jsonSerialize();
}
}
11 changes: 11 additions & 0 deletions src/Model/Actor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ public function getRole() {
return $this->role;
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {

$output = parent::jsonSerialize();
$output ["role"] = $this->getContent();

return $output;
}

/**
* Set the role.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Model/Aspect.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
class Aspect extends AbstractModel {

use StringContentTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ public function getStereo() {
return $this->stereo;
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"present" => $this->getPresent(),
"stereo" => $this->getStereo(),
];
}

/**
* Get the stereo.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Model/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Category extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
12 changes: 12 additions & 0 deletions src/Model/Channel.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public function getId() {
return $this->id;
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"displayNames" => static::serializeArray($this->getDisplayNames()),
"icons" => static::serializeArray($this->getIcons()),
"id" => $this->getId(),
"urls" => static::serializeArray($this->getUrls()),
];
}

/**
* Set the id.
*
Expand Down
9 changes: 9 additions & 0 deletions src/Model/Colour.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
class Colour extends AbstractModel {

use StringContentTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Country.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Country extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
18 changes: 18 additions & 0 deletions src/Model/Credits.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,22 @@ public function __construct() {
$this->setProducers([]);
$this->setWriters([]);
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"actors" => static::serializeArray($this->getActors()),
"adapters" => static::serializeArray($this->getAdapters()),
"commentators" => static::serializeArray($this->getCommentators()),
"composers" => static::serializeArray($this->getComposers()),
"directors" => static::serializeArray($this->getDirectors()),
"editors" => static::serializeArray($this->getEditors()),
"guests" => static::serializeArray($this->getGuests()),
"presenters" => static::serializeArray($this->getPresenters()),
"producers" => static::serializeArray($this->getProducers()),
"writers" => static::serializeArray($this->getWriters()),
];
}
}
9 changes: 9 additions & 0 deletions src/Model/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
class Date extends AbstractModel {

use StringContentTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Desc.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Desc extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/DisplayName.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class DisplayName extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/EpisodeNum.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,14 @@ public static function enumSystem() {
self::SYSTEM_XMLTV_NS,
];
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"system" => $this->getSystem(),
];
}
}
11 changes: 11 additions & 0 deletions src/Model/Icon.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,17 @@ public function getSrc() {
return $this->src;
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"height" => $this->getHeight(),
"src" => $this->getSrc(),
"width" => $this->getWidth(),
];
}

/**
* Set the source.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Model/Keyword.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Keyword extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Language.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Language extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/LastChance.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class LastChance extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Length.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,16 @@ public function getUnits() {
return $this->units;
}

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"units" => $this->getUnits(),
];
}

/**
* Set the units.
*
Expand Down
10 changes: 10 additions & 0 deletions src/Model/OrigLanguage.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class OrigLanguage extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
10 changes: 10 additions & 0 deletions src/Model/Premiere.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,14 @@ class Premiere extends AbstractModel {

use StringContentTrait;
use StringLangTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
"lang" => $this->getLang(),
];
}
}
9 changes: 9 additions & 0 deletions src/Model/Present.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
class Present extends AbstractModel {

use StringContentTrait;

/**
* {@inheritDoc}
*/
public function jsonSerialize() {
return [
"content" => $this->getContent(),
];
}
}
Loading

0 comments on commit 313cea0

Please sign in to comment.