* @license http://www.apache.org/licenses/LICENSE-2.0 * @package EPGService\Entities */ final class ProgramEntity { /** * @var string[] */ private array $categories; /** * @var string */ private string $channel_id; /** * @var string[] */ private array $countries; /** * @var \EPGService\Entities\Program\CreditEntity[] */ private array $credits; /** * @var \DateTime */ private DateTime $date; /** * @var string */ private string $description; /** * @var string[] */ private array $icons; /** * @var string */ private string $parents_guide; /** * @var string[] */ private array $productions; /** * @var \DateTime */ private DateTime $start; /** * @var \DateTime */ private DateTime $stop; /** * @var string */ private string $sub_title; /** * @var string */ private string $title; /** * @var string */ private string $year; /** * @param array $payload */ private function __construct(array $payload) { $this->categories = $payload['categories']; $this->channel_id = $payload['channel_id']; $this->countries = $payload['countries']; $this->credits = $payload['credits']; $this->date = $payload['date']; $this->description = $payload['description']; $this->icons = $payload['icons']; $this->parents_guide = $payload['parents_guide']; $this->productions = $payload['productions']; $this->start = $payload['start']; $this->stop = $payload['stop']; $this->sub_title = $payload['sub_title']; $this->title = $payload['title']; $this->year = $payload['year']; } /** * @param array $payload * * @return \EPGService\Entities\ProgramEntity * * @throws \RuntimeException */ public static function create(array $payload): ProgramEntity { if (!is_array($payload['categories'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['channel_id'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_array($payload['countries'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_array($payload['credits'])) { throw new RuntimeException('blah-blah-blah'); } if (!$payload['date'] instanceof DateTime) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['description'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_array($payload['icons'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['parents_guide'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_array($payload['productions'])) { throw new RuntimeException('blah-blah-blah'); } if (!$payload['start'] instanceof DateTime) { throw new RuntimeException('blah-blah-blah'); } if (!$payload['stop'] instanceof DateTime) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['sub_title'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['title'])) { throw new RuntimeException('blah-blah-blah'); } if (!is_string($payload['year'])) { throw new RuntimeException('blah-blah-blah'); } return new ProgramEntity($payload); } /** * @param string $name * * @return mixed */ public function __get(string $name) { return $this->$name; } /** * @param string $name * @param mixed $value * * @throws \RuntimeException */ public function __set(string $name, $value) { throw new RuntimeException('blah-blah-blah'); } }