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;
|
||||
}
|
||||
|
|
|
@ -160,23 +160,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,
|
||||
'duration' => $this->duration,
|
||||
'performer' => $this->performer,
|
||||
'title' => $this->title
|
||||
|
@ -188,29 +184,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 InputMediaAudio();
|
||||
$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->duration = $data['duration'];
|
||||
$object->performer = $data['performer'];
|
||||
$object->title = $data['title'];
|
||||
$object->type = $data['type'] ?? null;
|
||||
$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->duration = $data['duration'] ?? null;
|
||||
$object->performer = $data['performer'] ?? null;
|
||||
$object->title = $data['title'] ?? null;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
|
|
@ -132,23 +132,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,
|
||||
'disable_content_type_detection' => $this->disable_content_type_detection,
|
||||
];
|
||||
}
|
||||
|
@ -158,27 +154,21 @@
|
|||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
$caption_entities = null;
|
||||
if (isset($data['caption_entities']))
|
||||
{
|
||||
$caption_entities = [];
|
||||
foreach ($data['caption_entities'] as $caption_entity)
|
||||
{
|
||||
$caption_entities[] = MessageEntity::fromArray($caption_entity);
|
||||
}
|
||||
}
|
||||
|
||||
$object = new InputMediaDocument();
|
||||
$object->type = $data['type'];
|
||||
$object->media = $data['media'];
|
||||
$object->type = $data['type'] ?? null;
|
||||
$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 = $caption_entities;
|
||||
$object->disable_content_type_detection = $data['disable_content_type_detection'];
|
||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
||||
{
|
||||
return MessageEntity::fromArray($item);
|
||||
}, $data['caption_entities']) : null;
|
||||
$object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
@ -192,6 +182,7 @@
|
|||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument
|
||||
{
|
||||
$object = new InputMediaDocument();
|
||||
|
||||
$object->type = $inputMedia->getType();
|
||||
$object->media = $inputMedia->getMedia();
|
||||
$object->thumb = $inputMedia->getThumb();
|
||||
|
|
|
@ -99,7 +99,7 @@
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHasSpoiler(): bool
|
||||
public function hasSpoiler(): bool
|
||||
{
|
||||
return $this->has_spoiler;
|
||||
}
|
||||
|
@ -111,22 +111,18 @@
|
|||
*/
|
||||
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,
|
||||
'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,
|
||||
'has_spoiler' => $this->has_spoiler,
|
||||
];
|
||||
}
|
||||
|
@ -141,20 +137,15 @@
|
|||
{
|
||||
$object = new self();
|
||||
|
||||
$object->type = $data['type'];
|
||||
$object->media = $data['media'];
|
||||
$object->caption = $data['caption'];
|
||||
$object->parse_mode = $data['parse_mode'];
|
||||
$object->has_spoiler = $data['has_spoiler'];
|
||||
|
||||
if (isset($data['caption_entities']))
|
||||
$object->type = $data['type'] ?? null;
|
||||
$object->media = $data['media'] ?? null;
|
||||
$object->caption = $data['caption'] ?? null;
|
||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
||||
$object->has_spoiler = $data['has_spoiler'] ?? null;
|
||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
||||
{
|
||||
$object->caption_entities = [];
|
||||
foreach ($data['caption_entities'] as $caption_entity)
|
||||
{
|
||||
$object->caption_entities[] = MessageEntity::fromArray($caption_entity);
|
||||
}
|
||||
}
|
||||
return MessageEntity::fromArray($item);
|
||||
}, $data['caption_entities']) : null;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
@ -173,16 +164,8 @@
|
|||
$object->media = $inputMedia->getMedia();
|
||||
$object->caption = $inputMedia->getCaption();
|
||||
$object->parse_mode = $inputMedia->getParseMode();
|
||||
$object->has_spoiler = $inputMedia->isHasSpoiler();
|
||||
|
||||
if ($inputMedia->getCaptionEntities())
|
||||
{
|
||||
$object->caption_entities = [];
|
||||
foreach ($inputMedia->getCaptionEntities() as $caption_entity)
|
||||
{
|
||||
$object->caption_entities[] = MessageEntity::fromArray($caption_entity);
|
||||
}
|
||||
}
|
||||
$object->has_spoiler = $inputMedia->hasSpoiler();
|
||||
$object->caption_entities = $inputMedia->getCaptionEntities();
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isSupportsStreaming(): bool
|
||||
public function supportsStreaming(): bool
|
||||
{
|
||||
return $this->supports_streaming;
|
||||
}
|
||||
|
@ -179,7 +179,7 @@
|
|||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isHasSpoiler(): bool
|
||||
public function hasSpoiler(): bool
|
||||
{
|
||||
return $this->has_spoiler;
|
||||
}
|
||||
|
@ -191,23 +191,19 @@
|
|||
*/
|
||||
public function toArray(): array
|
||||
{
|
||||
$caption_entities = null;
|
||||
if($this->getCaptionEntities() !== null)
|
||||
{
|
||||
$caption_entities = [];
|
||||
foreach ($this->getCaptionEntities() 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,
|
||||
|
@ -221,32 +217,26 @@
|
|||
*
|
||||
* @param array $data
|
||||
* @return ObjectTypeInterface
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function fromArray(array $data): ObjectTypeInterface
|
||||
{
|
||||
$caption_entities = null;
|
||||
if($data['caption_entities'] !== null)
|
||||
{
|
||||
$caption_entities = [];
|
||||
foreach ($data['caption_entities'] as $caption_entity)
|
||||
{
|
||||
$caption_entities[] = MessageEntity::fromArray($caption_entity);
|
||||
}
|
||||
}
|
||||
|
||||
$object = new InputMediaVideo();
|
||||
|
||||
$object->type = $data['type'];
|
||||
$object->media = $data['media'];
|
||||
$object->thumb = @$data['thumb'] ?? null;
|
||||
$object->caption = @$data['caption'] ?? null;
|
||||
$object->parse_mode = @$data['parse_mode'] ?? null;
|
||||
$object->caption_entities = $caption_entities;
|
||||
$object->width = @$data['width'] ?? null;
|
||||
$object->height = @$data['height'] ?? null;
|
||||
$object->duration = @$data['duration'] ?? null;
|
||||
$object->supports_streaming = @$data['supports_streaming'] ?? false;
|
||||
$object->has_spoiler = @$data['has_spoiler'] ?? false;
|
||||
$object->type = $data['type'] ?? null;
|
||||
$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->supports_streaming = $data['supports_streaming'] ?? false;
|
||||
$object->has_spoiler = $data['has_spoiler'] ?? false;
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
@ -256,6 +246,7 @@
|
|||
*
|
||||
* @param InputMedia $inputMedia
|
||||
* @return InputMediaVideo
|
||||
* @noinspection DuplicatedCode
|
||||
*/
|
||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo
|
||||
{
|
||||
|
@ -271,7 +262,7 @@
|
|||
$object->height = $inputMedia->getHeight();
|
||||
$object->duration = $inputMedia->getDuration();
|
||||
$object->supports_streaming = $inputMedia->isSupportsStreaming();
|
||||
$object->has_spoiler = $inputMedia->isHasSpoiler();
|
||||
$object->has_spoiler = $inputMedia->hasSpoiler();
|
||||
|
||||
return $object;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue