Major Refactoring
This commit is contained in:
parent
3de87df2d9
commit
54a8a59ee8
83 changed files with 892 additions and 918 deletions
|
@ -4,6 +4,7 @@
|
|||
|
||||
namespace TgBotLib\Objects\InputMedia;
|
||||
|
||||
use TgBotLib\Abstracts\InputMediaType;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\InputMedia;
|
||||
use TgBotLib\Objects\MessageEntity;
|
||||
|
@ -61,6 +62,8 @@
|
|||
private $has_spoiler;
|
||||
|
||||
/**
|
||||
* Type of the result, must be animation
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
|
@ -163,7 +166,7 @@
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHasSpoiler(): bool
|
||||
public function hasSpoiler(): bool
|
||||
{
|
||||
return $this->has_spoiler;
|
||||
}
|
||||
|
@ -175,23 +178,19 @@
|
|||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$caption_entities = null;
|
||||
if ($this->caption_entities)
|
||||
{
|
||||
$caption_entities = [];
|
||||
foreach ($this->caption_entities as $caption_entity)
|
||||
{
|
||||
$caption_entities[] = $caption_entity->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'type' => $this->type,
|
||||
'media' => $this->media,
|
||||
'thumb' => $this->thumb,
|
||||
'caption' => $this->caption,
|
||||
'parse_mode' => $this->parse_mode,
|
||||
'caption_entities' => $caption_entities,
|
||||
'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) {
|
||||
if($item instanceof ObjectTypeInterface)
|
||||
{
|
||||
return $item->toArray();
|
||||
}
|
||||
return $item;
|
||||
}, $this->caption_entities) : null,
|
||||
'width' => $this->width,
|
||||
'height' => $this->height,
|
||||
'duration' => $this->duration,
|
||||
|
@ -204,30 +203,24 @@
|
|||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
$caption_entities = null;
|
||||
if ($data['caption_entities'])
|
||||
{
|
||||
$caption_entities = [];
|
||||
foreach ($data['caption_entities'] as $caption_entity)
|
||||
{
|
||||
$caption_entities[] = MessageEntity::fromArray($caption_entity);
|
||||
}
|
||||
}
|
||||
|
||||
$object = new static();
|
||||
$object->type = $data['type'];
|
||||
$object->media = $data['media'];
|
||||
$object->thumb = $data['thumb'];
|
||||
$object->caption = $data['caption'];
|
||||
$object->parse_mode = $data['parse_mode'];
|
||||
$object->caption_entities = $caption_entities;
|
||||
$object->width = $data['width'];
|
||||
$object->height = $data['height'];
|
||||
$object->duration = $data['duration'];
|
||||
$object->has_spoiler = $data['has_spoiler'];
|
||||
$object->type = $data['type'] ?? InputMediaType::Animation;
|
||||
$object->media = $data['media'] ?? null;
|
||||
$object->thumb = $data['thumb'] ?? null;
|
||||
$object->caption = $data['caption'] ?? null;
|
||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
||||
{
|
||||
return MessageEntity::fromArray($item);
|
||||
}, $data['caption_entities']) : null;
|
||||
$object->width = $data['width'] ?? null;
|
||||
$object->height = $data['height'] ?? null;
|
||||
$object->duration = $data['duration'] ?? null;
|
||||
$object->has_spoiler = $data['has_spoiler'] ?? false;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
@ -237,6 +230,7 @@
|
|||
*
|
||||
* @param InputMedia $inputMedia
|
||||
* @return InputMediaAnimation
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation
|
||||
{
|
||||
|
@ -251,7 +245,7 @@
|
|||
$object->width = $inputMedia->getWidth();
|
||||
$object->height = $inputMedia->getHeight();
|
||||
$object->duration = $inputMedia->getDuration();
|
||||
$object->has_spoiler = $inputMedia->isHasSpoiler();
|
||||
$object->has_spoiler = $inputMedia->hasSpoiler();
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue