Updated Game object
This commit is contained in:
parent
6f75038bf5
commit
f966d6809f
1 changed files with 20 additions and 46 deletions
|
@ -10,35 +10,18 @@
|
||||||
|
|
||||||
class Game implements ObjectTypeInterface
|
class Game implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $title;
|
||||||
* @var string
|
private string $description;
|
||||||
*/
|
|
||||||
private $title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
private $description;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var PhotoSize[]
|
* @var PhotoSize[]
|
||||||
*/
|
*/
|
||||||
private $photo;
|
private array $photo;
|
||||||
|
private ?string $text;
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $text;
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $text_entities;
|
private ?array $text_entities;
|
||||||
|
private ?Animation $animation;
|
||||||
/**
|
|
||||||
* @var Animation|null
|
|
||||||
*/
|
|
||||||
private $animation;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Title of the game
|
* Title of the game
|
||||||
|
@ -106,46 +89,37 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of this object.
|
* @inheritDocll
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'title' => $this->title,
|
'title' => $this->title,
|
||||||
'description' => $this->description,
|
'description' => $this->description,
|
||||||
'photo' => isset($this->photo) ? array_map(function ($photo) {
|
'photo' => isset($this->photo) ? array_map(fn(PhotoSize $item) => $item->toArray(), $this->photo) : null,
|
||||||
return $photo->toArray();
|
|
||||||
}, $this->photo) : null,
|
|
||||||
'text' => $this->text,
|
'text' => $this->text,
|
||||||
'text_entities' => isset($this->text_entities) ? array_map(function ($text_entity) {
|
'text_entities' => isset($this->text_entities) ? array_map(fn(MessageEntity $item) => $item->toArray(), $this->text_entities) : null,
|
||||||
return $text_entity->toArray();
|
'animation' => $this->animation?->toArray(),
|
||||||
}, $this->text_entities) : null,
|
|
||||||
'animation' => ($this->animation instanceof ObjectTypeInterface) ? $this->animation->toArray() : null,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from an array representation
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return Game
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): ?Game
|
||||||
{
|
{
|
||||||
$object = new self();
|
if($data === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$object = new self();
|
||||||
$object->description = $data['description'] ?? null;
|
$object->description = $data['description'] ?? null;
|
||||||
$object->title = $data['title'] ?? null;
|
$object->title = $data['title'] ?? null;
|
||||||
$object->photo = isset($data['photo']) && is_array($data['photo']) ? array_map(function ($photo) {
|
$object->photo = isset($data['photo']) ? array_map(fn(array $items) => PhotoSize::fromArray($items), $data['photo'] ?? []) : null;
|
||||||
return PhotoSize::fromArray($photo);
|
|
||||||
}, $data['photo']) : null;
|
|
||||||
$object->text = $data['text'] ?? null;
|
$object->text = $data['text'] ?? null;
|
||||||
$object->text_entities = isset($data['text_entities']) && is_array($data['text_entities']) ? array_map(function ($text_entity) {
|
$object->text_entities = ($data['text_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['text_entities']) : null;
|
||||||
return MessageEntity::fromArray($text_entity);
|
$object->animation = isset($data['animation']) ? Animation::fromArray($data['animation']) : null;
|
||||||
}, $data['text_entities']) : null;
|
|
||||||
$object->animation = ($data['animation']) ? Animation::fromArray($data['animation']) : null;
|
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue