2023-02-13 20:34:11 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2023-02-14 17:41:38 -05:00
|
|
|
namespace TgBotLib\Objects\Telegram;
|
2023-02-13 20:34:11 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
2023-02-14 17:41:38 -05:00
|
|
|
use TgBotLib\Objects\Telegram\BotCommandScope\BotCommandScopeChat;
|
|
|
|
use TgBotLib\Objects\Telegram\BotCommandScope\BotCommandScopeChatAdministrators;
|
|
|
|
use TgBotLib\Objects\Telegram\BotCommandScope\BotCommandScopeChatMember;
|
2023-02-13 20:34:11 -05:00
|
|
|
|
|
|
|
class BotCommandScope implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|int|null
|
|
|
|
*/
|
|
|
|
private $chat_id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int|null
|
|
|
|
*/
|
|
|
|
private $user_id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope type, one of “default”, “all_private_chats”, “all_group_chats”, “all_chat_administrators”, “chat”,
|
|
|
|
* “chat_administrators”, “chat_member”
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique identifier for the target chat or username of the target supergroup (in the format @supergroupusername)
|
|
|
|
*
|
|
|
|
* @return int|string|null
|
|
|
|
*/
|
|
|
|
public function getChatId(): int|string|null
|
|
|
|
{
|
|
|
|
return $this->chat_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unique identifier of the target user
|
|
|
|
*
|
|
|
|
* @return int|null
|
|
|
|
*/
|
|
|
|
public function getUserId(): ?int
|
|
|
|
{
|
|
|
|
return $this->user_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => $this->type,
|
|
|
|
'chat_id' => $this->chat_id,
|
|
|
|
'user_id' => $this->user_id,
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs object from an array representation
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return BotCommandScope
|
2023-02-13 20:34:11 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-13 20:34:11 -05:00
|
|
|
{
|
2023-02-14 17:35:16 -05:00
|
|
|
if(isset($data['type']))
|
|
|
|
{
|
|
|
|
switch($data['type'])
|
|
|
|
{
|
|
|
|
case 'chat':
|
|
|
|
return BotCommandScopeChat::fromArray($data);
|
|
|
|
case 'chat_administrators':
|
|
|
|
return BotCommandScopeChatAdministrators::fromArray($data);
|
|
|
|
case 'chat_member':
|
|
|
|
return BotCommandScopeChatMember::fromArray($data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-13 20:34:11 -05:00
|
|
|
$object = new self();
|
|
|
|
|
2023-02-14 17:35:16 -05:00
|
|
|
$object->type = $data['type'] ?? null;
|
2023-02-13 20:34:11 -05:00
|
|
|
$object->chat_id = $data['chat_id'] ?? null;
|
|
|
|
$object->user_id = $data['user_id'] ?? null;
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|