Updated InputMedia objects
This commit is contained in:
parent
1d11ef3b2a
commit
3774b7f8c0
7 changed files with 113 additions and 415 deletions
10
src/TgBotLib/Enums/Types/ParseMode.php
Normal file
10
src/TgBotLib/Enums/Types/ParseMode.php
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace TgBotLib\Enums\Types;
|
||||||
|
|
||||||
|
enum ParseMode : string
|
||||||
|
{
|
||||||
|
case HTML = 'HTML';
|
||||||
|
case MARKDOWN = 'Markdown';
|
||||||
|
case MARKDOWN_V2 = 'MarkdownV2';
|
||||||
|
}
|
|
@ -15,17 +15,14 @@
|
||||||
|
|
||||||
abstract class InputMedia implements ObjectTypeInterface
|
abstract class InputMedia implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
protected InputMediaType $type;
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
protected $type;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Type of the result, can be photo, video, animation, audio or document
|
* Type of the result, can be photo, video, animation, audio or document
|
||||||
*
|
*
|
||||||
* @return string
|
* @return InputMediaType
|
||||||
*/
|
*/
|
||||||
public function getType(): string
|
public function getType(): InputMediaType
|
||||||
{
|
{
|
||||||
return $this->type;
|
return $this->type;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,71 +5,25 @@
|
||||||
namespace TgBotLib\Objects\InputMedia;
|
namespace TgBotLib\Objects\InputMedia;
|
||||||
|
|
||||||
use TgBotLib\Enums\Types\InputMediaType;
|
use TgBotLib\Enums\Types\InputMediaType;
|
||||||
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
use TgBotLib\Objects\InputMedia;
|
use TgBotLib\Objects\InputMedia;
|
||||||
use TgBotLib\Objects\MessageEntity;
|
use TgBotLib\Objects\MessageEntity;
|
||||||
|
|
||||||
class InputMediaAnimation implements ObjectTypeInterface
|
class InputMediaAnimation extends InputMedia implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $media;
|
||||||
* @var string
|
private ?string $thumb;
|
||||||
*/
|
private ?string $caption;
|
||||||
private $type;
|
private ?ParseMode $parse_mode;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $thumb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $caption;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $parse_mode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $caption_entities;
|
private ?array $caption_entities;
|
||||||
|
private ?int $width;
|
||||||
/**
|
private ?int $height;
|
||||||
* @var int|null
|
private ?int $duration;
|
||||||
*/
|
private bool $has_spoiler;
|
||||||
private $width;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $height;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $has_spoiler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of the result, must be animation
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType(): string
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
||||||
|
@ -114,9 +68,9 @@
|
||||||
* Optional. Mode for parsing entities in the animation caption.
|
* Optional. Mode for parsing entities in the animation caption.
|
||||||
*
|
*
|
||||||
* @see https://core.telegram.org/bots/api#formatting-options
|
* @see https://core.telegram.org/bots/api#formatting-options
|
||||||
* @return string|null
|
* @return ParseMode|null
|
||||||
*/
|
*/
|
||||||
public function getParseMode(): ?string
|
public function getParseMode(): ?ParseMode
|
||||||
{
|
{
|
||||||
return $this->parse_mode;
|
return $this->parse_mode;
|
||||||
}
|
}
|
||||||
|
@ -172,25 +126,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object.
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type->value,
|
||||||
'media' => $this->media,
|
'media' => $this->media,
|
||||||
'thumb' => $this->thumb,
|
'thumb' => $this->thumb,
|
||||||
'caption' => $this->caption,
|
'caption' => $this->caption,
|
||||||
'parse_mode' => $this->parse_mode,
|
'parse_mode' => $this->parse_mode->value,
|
||||||
'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) {
|
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
||||||
if($item instanceof ObjectTypeInterface)
|
|
||||||
{
|
|
||||||
return $item->toArray();
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}, $this->caption_entities) : null,
|
|
||||||
'width' => $this->width,
|
'width' => $this->width,
|
||||||
'height' => $this->height,
|
'height' => $this->height,
|
||||||
'duration' => $this->duration,
|
'duration' => $this->duration,
|
||||||
|
@ -199,24 +145,22 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from an array representation.
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return InputMediaAnimation
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): ?InputMediaAnimation
|
||||||
{
|
{
|
||||||
|
if($data === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$object = new static();
|
$object = new static();
|
||||||
$object->type = $data['type'] ?? InputMediaType::ANIMATION;
|
$object->type = $data['type'] ?? InputMediaType::ANIMATION;
|
||||||
$object->media = $data['media'] ?? null;
|
$object->media = $data['media'] ?? null;
|
||||||
$object->thumb = $data['thumb'] ?? null;
|
$object->thumb = $data['thumb'] ?? null;
|
||||||
$object->caption = $data['caption'] ?? null;
|
$object->caption = $data['caption'] ?? null;
|
||||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
$object->parse_mode = isset($data['parse_mode']) ? ParseMode::tryFrom($data['parse_mode']) ?? null : null;
|
||||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
$object->caption_entities = array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []);
|
||||||
{
|
|
||||||
return MessageEntity::fromArray($item);
|
|
||||||
}, $data['caption_entities']) : null;
|
|
||||||
$object->width = $data['width'] ?? null;
|
$object->width = $data['width'] ?? null;
|
||||||
$object->height = $data['height'] ?? null;
|
$object->height = $data['height'] ?? null;
|
||||||
$object->duration = $data['duration'] ?? null;
|
$object->duration = $data['duration'] ?? null;
|
||||||
|
@ -224,29 +168,4 @@
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs object from InputMedia
|
|
||||||
*
|
|
||||||
* @param InputMedia $inputMedia
|
|
||||||
* @return InputMediaAnimation
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
|
||||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaAnimation
|
|
||||||
{
|
|
||||||
$object = new static();
|
|
||||||
|
|
||||||
$object->type = $inputMedia->getType();
|
|
||||||
$object->media = $inputMedia->getMedia();
|
|
||||||
$object->thumb = $inputMedia->getThumb();
|
|
||||||
$object->caption = $inputMedia->getCaption();
|
|
||||||
$object->parse_mode = $inputMedia->getParseMode();
|
|
||||||
$object->caption_entities = $inputMedia->getCaptionEntities();
|
|
||||||
$object->width = $inputMedia->getWidth();
|
|
||||||
$object->height = $inputMedia->getHeight();
|
|
||||||
$object->duration = $inputMedia->getDuration();
|
|
||||||
$object->has_spoiler = $inputMedia->hasSpoiler();
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,66 +4,24 @@
|
||||||
|
|
||||||
namespace TgBotLib\Objects\InputMedia;
|
namespace TgBotLib\Objects\InputMedia;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
use TgBotLib\Objects\InputMedia;
|
use TgBotLib\Objects\InputMedia;
|
||||||
use TgBotLib\Objects\MessageEntity;
|
use TgBotLib\Objects\MessageEntity;
|
||||||
|
|
||||||
class InputMediaAudio implements ObjectTypeInterface
|
class InputMediaAudio extends InputMedia implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $media;
|
||||||
* @var string
|
private ?string $thumb;
|
||||||
*/
|
private ?string $caption;
|
||||||
private $type;
|
private ?ParseMode $parse_mode;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $thumb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $caption;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $parse_mode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $caption_entities;
|
private ?array $caption_entities;
|
||||||
|
private ?int $duration;
|
||||||
/**
|
private ?string $performer;
|
||||||
* @var int|null
|
private ?string $title;
|
||||||
*/
|
|
||||||
private $duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $performer;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $title;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of the result, must be audio
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType(): string
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
||||||
|
@ -106,9 +64,9 @@
|
||||||
/**
|
/**
|
||||||
* Optional. Mode for parsing entities in the audio caption.
|
* Optional. Mode for parsing entities in the audio caption.
|
||||||
*
|
*
|
||||||
* @return string|null
|
* @return ParseMode|null
|
||||||
*/
|
*/
|
||||||
public function getParseMode(): ?string
|
public function getParseMode(): ?ParseMode
|
||||||
{
|
{
|
||||||
return $this->parse_mode;
|
return $this->parse_mode;
|
||||||
}
|
}
|
||||||
|
@ -154,25 +112,17 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type?->value,
|
||||||
'media' => $this->media,
|
'media' => $this->media,
|
||||||
'thumb' => $this->thumb,
|
'thumb' => $this->thumb,
|
||||||
'caption' => $this->caption,
|
'caption' => $this->caption,
|
||||||
'parse_mode' => $this->parse_mode,
|
'parse_mode' => $this->parse_mode->value,
|
||||||
'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) {
|
'caption_entities' => is_null($this->caption_entities) ? null : array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
||||||
if($item instanceof ObjectTypeInterface)
|
|
||||||
{
|
|
||||||
return $item->toArray();
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}, $this->caption_entities) : null,
|
|
||||||
'duration' => $this->duration,
|
'duration' => $this->duration,
|
||||||
'performer' => $this->performer,
|
'performer' => $this->performer,
|
||||||
'title' => $this->title
|
'title' => $this->title
|
||||||
|
@ -180,51 +130,26 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from an array representation
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return InputMediaAudio
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): ?InputMediaAudio
|
||||||
{
|
{
|
||||||
|
if($data === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$object = new InputMediaAudio();
|
$object = new InputMediaAudio();
|
||||||
$object->type = $data['type'] ?? null;
|
$object->type = $data['type'] ?? null;
|
||||||
$object->media = $data['media'] ?? null;
|
$object->media = $data['media'] ?? null;
|
||||||
$object->thumb = $data['thumb'] ?? null;
|
$object->thumb = $data['thumb'] ?? null;
|
||||||
$object->caption = $data['caption'] ?? null;
|
$object->caption = $data['caption'] ?? null;
|
||||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
$object->parse_mode = isset($data['parse_mode']) ? ParseMode::tryFrom($data['parse_mode']) ?? null : null;
|
||||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []) : null;
|
||||||
{
|
|
||||||
return MessageEntity::fromArray($item);
|
|
||||||
}, $data['caption_entities']) : null;
|
|
||||||
$object->duration = $data['duration'] ?? null;
|
$object->duration = $data['duration'] ?? null;
|
||||||
$object->performer = $data['performer'] ?? null;
|
$object->performer = $data['performer'] ?? null;
|
||||||
$object->title = $data['title'] ?? null;
|
$object->title = $data['title'] ?? null;
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs object from an InputMedia object
|
|
||||||
*
|
|
||||||
* @param InputMedia $inputMedia
|
|
||||||
* @return InputMediaAudio
|
|
||||||
*/
|
|
||||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaAudio
|
|
||||||
{
|
|
||||||
$object = new InputMediaAudio();
|
|
||||||
$object->type = $inputMedia->getType();
|
|
||||||
$object->media = $inputMedia->getMedia();
|
|
||||||
$object->thumb = $inputMedia->getThumb();
|
|
||||||
$object->caption = $inputMedia->getCaption();
|
|
||||||
$object->parse_mode = $inputMedia->getParseMode();
|
|
||||||
$object->caption_entities = $inputMedia->getCaptionEntities();
|
|
||||||
$object->duration = $inputMedia->getDuration();
|
|
||||||
$object->performer = $inputMedia->getPerformer();
|
|
||||||
$object->title = $inputMedia->getTitle();
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,56 +4,22 @@
|
||||||
|
|
||||||
namespace TgBotLib\Objects\InputMedia;
|
namespace TgBotLib\Objects\InputMedia;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
use TgBotLib\Objects\InputMedia;
|
use TgBotLib\Objects\InputMedia;
|
||||||
use TgBotLib\Objects\MessageEntity;
|
use TgBotLib\Objects\MessageEntity;
|
||||||
|
|
||||||
class InputMediaDocument implements ObjectTypeInterface
|
class InputMediaDocument extends InputMedia implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $media;
|
||||||
* @var string
|
private ?string $thumb;
|
||||||
*/
|
private ?string $caption;
|
||||||
private $type;
|
private ?ParseMode $parse_mode;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $thumb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $caption;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $parse_mode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $caption_entities;
|
private ?array $caption_entities;
|
||||||
|
private bool $disable_content_type_detection;
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $disable_content_type_detection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of the result, must be document
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType(): string
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
||||||
|
@ -97,9 +63,9 @@
|
||||||
* Optional. Mode for parsing entities in the document caption.
|
* Optional. Mode for parsing entities in the document caption.
|
||||||
*
|
*
|
||||||
* @see https://core.telegram.org/bots/api#formatting-options
|
* @see https://core.telegram.org/bots/api#formatting-options
|
||||||
* @return string|null
|
* @return ParseMode|null
|
||||||
*/
|
*/
|
||||||
public function getParseMode(): ?string
|
public function getParseMode(): ?ParseMode
|
||||||
{
|
{
|
||||||
return $this->parse_mode;
|
return $this->parse_mode;
|
||||||
}
|
}
|
||||||
|
@ -126,71 +92,40 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns an array representation of the object.
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @return array
|
|
||||||
*/
|
*/
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type->value,
|
||||||
'media' => $this->media,
|
'media' => $this->media,
|
||||||
'thumb' => $this->thumb,
|
'thumb' => $this->thumb,
|
||||||
'caption' => $this->caption,
|
'caption' => $this->caption,
|
||||||
'parse_mode' => $this->parse_mode,
|
'parse_mode' => $this->parse_mode->value,
|
||||||
'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) {
|
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
||||||
if($item instanceof ObjectTypeInterface)
|
|
||||||
{
|
|
||||||
return $item->toArray();
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}, $this->caption_entities) : null,
|
|
||||||
'disable_content_type_detection' => $this->disable_content_type_detection,
|
'disable_content_type_detection' => $this->disable_content_type_detection,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from an array representation.
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return InputMediaDocument
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): ?InputMediaDocument
|
||||||
{
|
{
|
||||||
|
if($data === null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
$object = new InputMediaDocument();
|
$object = new InputMediaDocument();
|
||||||
$object->type = $data['type'] ?? null;
|
$object->type = $data['type'] ?? null;
|
||||||
$object->media = $data['media'] ?? null;
|
$object->media = $data['media'] ?? null;
|
||||||
$object->thumb = $data['thumb'] ?? null;
|
$object->thumb = $data['thumb'] ?? null;
|
||||||
$object->caption = $data['caption'] ?? null;
|
$object->caption = $data['caption'] ?? null;
|
||||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
$object->parse_mode = isset($data['parse_mode']) ? ParseMode::tryFrom($data['parse_mode']) ?? null : null;
|
||||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
$object->caption_entities = array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []);
|
||||||
{
|
|
||||||
return MessageEntity::fromArray($item);
|
|
||||||
}, $data['caption_entities']) : null;
|
|
||||||
$object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false;
|
$object->disable_content_type_detection = $data['disable_content_type_detection'] ?? false;
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs object from an InputMedia object.
|
|
||||||
*
|
|
||||||
* @param InputMedia $inputMedia
|
|
||||||
* @return InputMediaDocument
|
|
||||||
*/
|
|
||||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaDocument
|
|
||||||
{
|
|
||||||
$object = new InputMediaDocument();
|
|
||||||
|
|
||||||
$object->type = $inputMedia->getType();
|
|
||||||
$object->media = $inputMedia->getMedia();
|
|
||||||
$object->thumb = $inputMedia->getThumb();
|
|
||||||
$object->caption = $inputMedia->getCaption();
|
|
||||||
$object->parse_mode = $inputMedia->getParseMode();
|
|
||||||
$object->caption_entities = $inputMedia->getCaptionEntities();
|
|
||||||
$object->disable_content_type_detection = $inputMedia->isDisableContentTypeDetection();
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
}
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
namespace TgBotLib\Objects\InputMedia;
|
namespace TgBotLib\Objects\InputMedia;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
use TgBotLib\Objects\InputMedia;
|
use TgBotLib\Objects\InputMedia;
|
||||||
use TgBotLib\Objects\MessageEntity;
|
use TgBotLib\Objects\MessageEntity;
|
||||||
|
@ -12,7 +13,7 @@
|
||||||
{
|
{
|
||||||
private string $media;
|
private string $media;
|
||||||
private ?string $caption;
|
private ?string $caption;
|
||||||
private ?string $parse_mode;
|
private ?ParseMode $parse_mode;
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
|
@ -46,9 +47,9 @@
|
||||||
* Optional. Mode for parsing entities in the photo caption.
|
* Optional. Mode for parsing entities in the photo caption.
|
||||||
*
|
*
|
||||||
* @see https://core.telegram.org/bots/api#formatting-options
|
* @see https://core.telegram.org/bots/api#formatting-options
|
||||||
* @return string|null
|
* @return ParseMode|null
|
||||||
*/
|
*/
|
||||||
public function getParseMode(): ?string
|
public function getParseMode(): ?ParseMode
|
||||||
{
|
{
|
||||||
return $this->parse_mode;
|
return $this->parse_mode;
|
||||||
}
|
}
|
||||||
|
@ -81,10 +82,10 @@
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type->value,
|
||||||
'media' => $this->media,
|
'media' => $this->media,
|
||||||
'caption' => $this->caption,
|
'caption' => $this->caption,
|
||||||
'parse_mode' => $this->parse_mode,
|
'parse_mode' => $this->parse_mode->value,
|
||||||
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
||||||
'has_spoiler' => $this->has_spoiler,
|
'has_spoiler' => $this->has_spoiler,
|
||||||
];
|
];
|
||||||
|
@ -104,7 +105,7 @@
|
||||||
$object->type = $data['type'] ?? null;
|
$object->type = $data['type'] ?? null;
|
||||||
$object->media = $data['media'] ?? null;
|
$object->media = $data['media'] ?? null;
|
||||||
$object->caption = $data['caption'] ?? null;
|
$object->caption = $data['caption'] ?? null;
|
||||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
$object->parse_mode = isset($data['parse_mode']) ? ParseMode::tryFrom($data['parse_mode']) ?? null : null;
|
||||||
$object->has_spoiler = $data['has_spoiler'] ?? null;
|
$object->has_spoiler = $data['has_spoiler'] ?? null;
|
||||||
$object->caption_entities = array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []);
|
$object->caption_entities = array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []);
|
||||||
|
|
||||||
|
|
|
@ -4,76 +4,26 @@
|
||||||
|
|
||||||
namespace TgBotLib\Objects\InputMedia;
|
namespace TgBotLib\Objects\InputMedia;
|
||||||
|
|
||||||
|
use TgBotLib\Enums\Types\ParseMode;
|
||||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||||
use TgBotLib\Objects\InputMedia;
|
use TgBotLib\Objects\InputMedia;
|
||||||
use TgBotLib\Objects\MessageEntity;
|
use TgBotLib\Objects\MessageEntity;
|
||||||
|
|
||||||
class InputMediaVideo implements ObjectTypeInterface
|
class InputMediaVideo extends InputMedia implements ObjectTypeInterface
|
||||||
{
|
{
|
||||||
/**
|
private string $media;
|
||||||
* @var string
|
private ?string $thumb;
|
||||||
*/
|
private ?string $caption;
|
||||||
private $type;
|
private ?ParseMode $parse_mode;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string
|
|
||||||
*/
|
|
||||||
private $media;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $thumb;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $caption;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var string|null
|
|
||||||
*/
|
|
||||||
private $parse_mode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var MessageEntity[]|null
|
* @var MessageEntity[]|null
|
||||||
*/
|
*/
|
||||||
private $caption_entities;
|
private ?array $caption_entities;
|
||||||
|
private ?int $width;
|
||||||
/**
|
private ?int $height;
|
||||||
* @var int|null
|
private ?string $duration;
|
||||||
*/
|
private bool $supports_streaming;
|
||||||
private $width;
|
private bool $has_spoiler;
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $height;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var int|null
|
|
||||||
*/
|
|
||||||
private $duration;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $supports_streaming;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
private $has_spoiler;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Type of the result, must be video
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*/
|
|
||||||
public function getType(): string
|
|
||||||
{
|
|
||||||
return $this->type;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended), pass an HTTP
|
||||||
|
@ -117,9 +67,9 @@
|
||||||
* Optional. Mode for parsing entities in the video caption.
|
* Optional. Mode for parsing entities in the video caption.
|
||||||
*
|
*
|
||||||
* @see https://core.telegram.org/bots/api#formatting-options
|
* @see https://core.telegram.org/bots/api#formatting-options
|
||||||
* @return string|null
|
* @return ParseMode|null
|
||||||
*/
|
*/
|
||||||
public function getParseMode(): ?string
|
public function getParseMode(): ?ParseMode
|
||||||
{
|
{
|
||||||
return $this->parse_mode;
|
return $this->parse_mode;
|
||||||
}
|
}
|
||||||
|
@ -192,18 +142,12 @@
|
||||||
public function toArray(): array
|
public function toArray(): array
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'type' => $this->type,
|
'type' => $this->type->value,
|
||||||
'media' => $this->media,
|
'media' => $this->media,
|
||||||
'thumb' => $this->thumb,
|
'thumb' => $this->thumb,
|
||||||
'caption' => $this->caption,
|
'caption' => $this->caption,
|
||||||
'parse_mode' => $this->parse_mode,
|
'parse_mode' => $this->parse_mode->value,
|
||||||
'caption_entities' => is_array($this->caption_entities) ? array_map(function ($item) {
|
'caption_entities' => array_map(fn(MessageEntity $item) => $item->toArray(), $this->caption_entities),
|
||||||
if($item instanceof ObjectTypeInterface)
|
|
||||||
{
|
|
||||||
return $item->toArray();
|
|
||||||
}
|
|
||||||
return $item;
|
|
||||||
}, $this->caption_entities) : null,
|
|
||||||
'width' => $this->width,
|
'width' => $this->width,
|
||||||
'height' => $this->height,
|
'height' => $this->height,
|
||||||
'duration' => $this->duration,
|
'duration' => $this->duration,
|
||||||
|
@ -213,13 +157,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs object from an array representation.
|
* @inheritDoc
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @return InputMediaVideo
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
*/
|
||||||
public static function fromArray(array $data): self
|
public static function fromArray(?array $data): InputMediaVideo
|
||||||
{
|
{
|
||||||
$object = new InputMediaVideo();
|
$object = new InputMediaVideo();
|
||||||
|
|
||||||
|
@ -228,10 +168,7 @@
|
||||||
$object->thumb = $data['thumb'] ?? null;
|
$object->thumb = $data['thumb'] ?? null;
|
||||||
$object->caption = $data['caption'] ?? null;
|
$object->caption = $data['caption'] ?? null;
|
||||||
$object->parse_mode = $data['parse_mode'] ?? null;
|
$object->parse_mode = $data['parse_mode'] ?? null;
|
||||||
$object->caption_entities = isset($data['caption_entities']) ? array_map(function ($item)
|
$object->caption_entities = isset($data['caption_entities']) ? array_map(fn(array $items) => MessageEntity::fromArray($items), $data['caption_entities'] ?? []) : null;
|
||||||
{
|
|
||||||
return MessageEntity::fromArray($item);
|
|
||||||
}, $data['caption_entities']) : null;
|
|
||||||
$object->width = $data['width'] ?? null;
|
$object->width = $data['width'] ?? null;
|
||||||
$object->height = $data['height'] ?? null;
|
$object->height = $data['height'] ?? null;
|
||||||
$object->duration = $data['duration'] ?? null;
|
$object->duration = $data['duration'] ?? null;
|
||||||
|
@ -240,30 +177,4 @@
|
||||||
|
|
||||||
return $object;
|
return $object;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructs object from an InputMedia object.
|
|
||||||
*
|
|
||||||
* @param InputMedia $inputMedia
|
|
||||||
* @return InputMediaVideo
|
|
||||||
* @noinspection DuplicatedCode
|
|
||||||
*/
|
|
||||||
public static function fromInputMedia(InputMedia $inputMedia): InputMediaVideo
|
|
||||||
{
|
|
||||||
$object = new InputMediaVideo();
|
|
||||||
|
|
||||||
$object->type = $inputMedia->getType();
|
|
||||||
$object->media = $inputMedia->getMedia();
|
|
||||||
$object->thumb = $inputMedia->getThumb();
|
|
||||||
$object->caption = $inputMedia->getCaption();
|
|
||||||
$object->parse_mode = $inputMedia->getParseMode();
|
|
||||||
$object->caption_entities = $inputMedia->getCaptionEntities();
|
|
||||||
$object->width = $inputMedia->getWidth();
|
|
||||||
$object->height = $inputMedia->getHeight();
|
|
||||||
$object->duration = $inputMedia->getDuration();
|
|
||||||
$object->supports_streaming = $inputMedia->isSupportsStreaming();
|
|
||||||
$object->has_spoiler = $inputMedia->hasSpoiler();
|
|
||||||
|
|
||||||
return $object;
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue