2023-02-13 20:27:09 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2023-02-14 17:41:38 -05:00
|
|
|
namespace TgBotLib\Objects\Telegram\BotCommandScope;
|
2023-02-13 20:27:09 -05:00
|
|
|
|
2023-08-09 15:32:45 -04:00
|
|
|
use TgBotLib\Enums\BotCommandScopeType;
|
2023-02-13 20:27:09 -05:00
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
2023-02-14 17:41:38 -05:00
|
|
|
use TgBotLib\Objects\Telegram\BotCommandScope;
|
2023-02-13 20:27:09 -05:00
|
|
|
|
|
|
|
class BotCommandScopeChat implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var int|string
|
|
|
|
*/
|
|
|
|
private $chat_id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scope type, must be chat
|
|
|
|
*
|
|
|
|
* @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
|
|
|
|
*/
|
|
|
|
public function getChatId(): int|string
|
|
|
|
{
|
|
|
|
return $this->chat_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => $this->type,
|
|
|
|
'chat_id' => $this->chat_id
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs object from an array representation
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return BotCommandScopeChat
|
2023-02-13 20:27:09 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-13 20:27:09 -05:00
|
|
|
{
|
|
|
|
$object = new self();
|
|
|
|
|
2023-08-09 15:32:45 -04:00
|
|
|
$object->type = $data['type'] ?? BotCommandScopeType::CHAT;
|
2023-02-14 17:35:16 -05:00
|
|
|
$object->chat_id = $data['chat_id'] ?? null;
|
2023-02-13 20:27:09 -05:00
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
2023-02-13 20:33:55 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs object from BotCommandScope
|
|
|
|
*
|
|
|
|
* @param BotCommandScope $botCommandScope
|
|
|
|
* @return static
|
|
|
|
*/
|
|
|
|
public static function fromBotCommandScope(BotCommandScope $botCommandScope): self
|
|
|
|
{
|
|
|
|
$object = new self();
|
|
|
|
|
|
|
|
$object->type = $botCommandScope->getType();
|
|
|
|
$object->chat_id = $botCommandScope->getChatId();
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
2023-02-13 20:27:09 -05:00
|
|
|
}
|