2023-02-13 21:46:57 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2023-02-14 17:41:38 -05:00
|
|
|
namespace TgBotLib\Objects\Telegram;
|
2023-02-13 21:46:57 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
|
|
|
|
|
|
|
class MenuButton implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
private $type;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string|null
|
|
|
|
*/
|
|
|
|
private $text;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var WebAppInfo|null
|
|
|
|
*/
|
|
|
|
private $web_app;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Type of the button, must be web_app
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
|
|
|
public function getType(): string
|
|
|
|
{
|
|
|
|
return $this->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Text on the button
|
|
|
|
*
|
|
|
|
* @return string|null
|
|
|
|
*/
|
|
|
|
public function getText(): ?string
|
|
|
|
{
|
|
|
|
return $this->text;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of the Web App that will be launched when the user presses the button. The Web App will be able
|
|
|
|
* to send an arbitrary message on behalf of the user using the method answerWebAppQuery.
|
|
|
|
*
|
|
|
|
* @return WebAppInfo|null
|
|
|
|
*/
|
|
|
|
public function getWebApp(): ?WebAppInfo
|
|
|
|
{
|
|
|
|
return $this->web_app;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object
|
|
|
|
*
|
|
|
|
* @return array
|
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => $this->type,
|
|
|
|
'text' => $this->text,
|
2023-02-14 17:35:16 -05:00
|
|
|
'web_app' => ($this->web_app instanceof ObjectTypeInterface) ? $this->web_app->toArray() : null
|
2023-02-13 21:46:57 -05:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs object from an array representation
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return MenuButton
|
2023-02-13 21:46:57 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-13 21:46:57 -05:00
|
|
|
{
|
|
|
|
$object = new self();
|
|
|
|
|
2023-02-14 17:35:16 -05:00
|
|
|
$object->type = $data['type'] ?? null;
|
2023-02-13 21:46:57 -05:00
|
|
|
$object->text = $data['text'] ?? null;
|
|
|
|
$object->web_app = ($data['web_app'] ?? null) ? WebAppInfo::fromArray($data['web_app']) : null;
|
|
|
|
|
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
}
|