Refactor media handling in InputMedia classes
This commit is contained in:
parent
427102a635
commit
0145279516
6 changed files with 32 additions and 7 deletions
|
@ -15,6 +15,7 @@
|
|||
abstract class InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
protected InputMediaType $type;
|
||||
protected string $media;
|
||||
|
||||
/**
|
||||
* Type of the result, can be photo, video, animation, audio or document
|
||||
|
@ -26,6 +27,30 @@
|
|||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* File to send. Pass a file_id to send a file that exists on the Telegram servers (recommended),
|
||||
* pass an HTTP URL for Telegram to get a file from the Internet, or pass “attach://<file_attach_name>” to
|
||||
* upload a new one using multipart/form-data under <file_attach_name> name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getMedia(): string
|
||||
{
|
||||
return $this->media;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the media content to upload
|
||||
*
|
||||
* @param string $media
|
||||
* @return $this
|
||||
*/
|
||||
public function setMedia(string $media): self
|
||||
{
|
||||
$this->media = $media;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
@ -46,6 +71,11 @@
|
|||
throw new InvalidArgumentException('type is not provided');
|
||||
}
|
||||
|
||||
if(!isset($data['media']))
|
||||
{
|
||||
throw new InvalidArgumentException('media is not provided');
|
||||
}
|
||||
|
||||
return match (InputMediaType::tryFrom($data['type']))
|
||||
{
|
||||
InputMediaType::PHOTO => InputMediaPhoto::fromArray($data),
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
|
||||
class InputMediaAnimation extends InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
private string $media;
|
||||
private ?string $thumb;
|
||||
private ?string $caption;
|
||||
private ?ParseMode $parse_mode;
|
||||
|
@ -29,7 +28,6 @@
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->media = (string)null;
|
||||
$this->thumb = null;
|
||||
$this->caption = null;
|
||||
$this->parse_mode = null;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
class InputMediaAudio extends InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
private string $media;
|
||||
private ?string $thumb;
|
||||
private ?string $caption;
|
||||
private ?ParseMode $parse_mode;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
class InputMediaDocument extends InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
private string $media;
|
||||
private ?string $thumb;
|
||||
private ?string $caption;
|
||||
private ?ParseMode $parse_mode;
|
||||
|
@ -25,7 +24,6 @@
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->media = (string)null;
|
||||
$this->thumb = null;
|
||||
$this->caption = null;
|
||||
$this->parse_mode = null;
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
namespace TgBotLib\Objects\InputMedia;
|
||||
|
||||
use TgBotLib\Enums\Types\InputMediaType;
|
||||
use TgBotLib\Enums\Types\ParseMode;
|
||||
use TgBotLib\Interfaces\ObjectTypeInterface;
|
||||
use TgBotLib\Objects\InputMedia;
|
||||
|
@ -10,7 +11,6 @@
|
|||
|
||||
class InputMediaPhoto extends InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
private string $media;
|
||||
private ?string $caption;
|
||||
private ?ParseMode $parse_mode;
|
||||
/**
|
||||
|
@ -24,6 +24,7 @@
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->type = InputMediaType::PHOTO;
|
||||
$this->media = '';
|
||||
$this->caption = null;
|
||||
$this->parse_mode = null;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
class InputMediaVideo extends InputMedia implements ObjectTypeInterface
|
||||
{
|
||||
private string $media;
|
||||
private ?string $thumb;
|
||||
private ?string $caption;
|
||||
private ?ParseMode $parse_mode;
|
||||
|
|
Loading…
Add table
Reference in a new issue