Added ReactionType objects

This commit is contained in:
netkas 2024-10-04 13:23:54 -04:00
parent 18ba52b376
commit ba5e446bd2
5 changed files with 190 additions and 0 deletions

View file

@ -0,0 +1,10 @@
<?php
namespace TgBotLib\Enums\Types;
enum ReactionTypes : string
{
case EMOJI = 'emoji';
case CUSTOM_EMOJI = 'custom_emoji';
case PAID = 'paid';
}

View file

@ -0,0 +1,40 @@
<?php
namespace TgBotLib\Objects;
use TgBotLib\Enums\Types\ReactionTypes;
use TgBotLib\Interfaces\ObjectTypeInterface;
abstract class ReactionType implements ObjectTypeInterface
{
protected ReactionTypes $type;
/**
* @inheritDoc
*/
public abstract function toArray(): ?array;
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?ReactionType
{
if($data === null)
{
return null;
}
if(!isset($data['type']))
{
throw new \InvalidArgumentException('Type is not provided');
}
return match(ReactionTypes::tryFrom($data['type']))
{
ReactionTypes::EMOJI => ReactionType\ReactionTypeEmoji::fromArray($data),
ReactionTypes::CUSTOM_EMOJI => ReactionType\ReactionTypeCustomEmoji::fromArray($data),
ReactionTypes::PAID => ReactionType\ReactionTypePaid::fromArray($data),
default => throw new \InvalidArgumentException('Unknown type')
};
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace TgBotLib\Objects\ReactionType;
use TgBotLib\Enums\Types\ReactionTypes;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ReactionType;
class ReactionTypeCustomEmoji extends ReactionType implements ObjectTypeInterface
{
private string $custom_emoji_id;
/**
* Custom emoji identifier
*
* @return string
*/
public function getCustomEmojiId(): string
{
return $this->custom_emoji_id;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'type' => $this->type->value,
'custom_emoji_id' => $this->custom_emoji_id
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?ReactionType
{
if($data === null)
{
return null;
}
$object = new self();
$object->type = ReactionTypes::CUSTOM_EMOJI;
$object->custom_emoji_id = $data['custom_emoji_id'];
return $object;
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace TgBotLib\Objects\ReactionType;
use TgBotLib\Enums\Types\ReactionTypes;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ReactionType;
class ReactionTypeEmoji extends ReactionType implements ObjectTypeInterface
{
private string $emoji;
/**
* Reaction emoji. Currently, it can be one of "👍", "👎", "", "🔥", "🥰", "👏", "😁", "🤔", "🤯", "😱",
* "🤬", "😢", "🎉", "🤩", "🤮", "💩", "🙏", "👌", "🕊", "🤡", "🥱", "🥴", "😍", "🐳", "❤‍🔥", "🌚", "🌭", "💯",
* "🤣", "", "🍌", "🏆", "💔", "🤨", "😐", "🍓", "🍾", "💋", "🖕", "😈", "😴", "😭", "🤓", "👻", "👨‍💻", "👀",
* "🎃", "🙈", "😇", "😨", "🤝", "", "🤗", "🫡", "🎅", "🎄", "", "💅", "🤪", "🗿", "🆒", "💘", "🙉", "🦄",
* "😘", "💊", "🙊", "😎", "👾", "🤷‍♂", "🤷", "🤷‍♀", "😡"
*
* @return string
*/
public function getEmoji(): string
{
return $this->emoji;
}
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'type' => $this->type->value,
'emoji' => $this->emoji
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?ReactionType
{
if($data === null)
{
return null;
}
$object = new self();
$object->type = ReactionTypes::EMOJI;
$object->emoji = $data['emoji'];
return $object;
}
}

View file

@ -0,0 +1,36 @@
<?php
namespace TgBotLib\Objects\ReactionType;
use TgBotLib\Enums\Types\ReactionTypes;
use TgBotLib\Interfaces\ObjectTypeInterface;
use TgBotLib\Objects\ReactionType;
class ReactionTypePaid extends ReactionType implements ObjectTypeInterface
{
/**
* @inheritDoc
*/
public function toArray(): ?array
{
return [
'type' => $this->type->value
];
}
/**
* @inheritDoc
*/
public static function fromArray(?array $data): ?ReactionType
{
if($data === null)
{
return null;
}
$object = new self();
$object->type = ReactionTypes::PAID;
return $object;
}
}