2023-02-13 13:57:03 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/** @noinspection PhpMissingFieldTypeInspection */
|
|
|
|
|
2023-02-14 17:41:38 -05:00
|
|
|
namespace TgBotLib\Objects\Telegram;
|
2023-02-13 13:57:03 -05:00
|
|
|
|
|
|
|
use TgBotLib\Interfaces\ObjectTypeInterface;
|
|
|
|
|
|
|
|
class InlineKeyboardMarkup implements ObjectTypeInterface
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var InlineKeyboardButton[][]
|
|
|
|
*/
|
|
|
|
private $inline_keyboard;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of button rows, each represented by an Array of InlineKeyboardButton objects
|
|
|
|
*
|
|
|
|
* @see https://core.telegram.org/bots/api#inlinekeyboardmarkup
|
|
|
|
* @return InlineKeyboardButton[][]
|
|
|
|
*/
|
|
|
|
public function getInlineKeyboard(): array
|
|
|
|
{
|
|
|
|
return $this->inline_keyboard;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array representation of the object
|
|
|
|
*
|
2023-02-14 17:35:16 -05:00
|
|
|
* @return array[][]
|
2023-02-13 13:57:03 -05:00
|
|
|
*/
|
|
|
|
public function toArray(): array
|
|
|
|
{
|
2023-02-14 17:35:16 -05:00
|
|
|
$data = [];
|
|
|
|
|
|
|
|
if ($this->inline_keyboard !== null)
|
|
|
|
{
|
|
|
|
/** @var InlineKeyboardButton $item */
|
|
|
|
foreach ($this->inline_keyboard as $item)
|
|
|
|
{
|
|
|
|
$data[][] = $item->toArray();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
2023-02-13 13:57:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructs the object from an array representation
|
|
|
|
*
|
|
|
|
* @param array $data
|
2023-02-16 15:27:57 -05:00
|
|
|
* @return InlineKeyboardMarkup
|
2023-02-13 13:57:03 -05:00
|
|
|
*/
|
2023-02-16 15:27:57 -05:00
|
|
|
public static function fromArray(array $data): self
|
2023-02-13 13:57:03 -05:00
|
|
|
{
|
|
|
|
$object = new self();
|
2023-02-14 17:35:16 -05:00
|
|
|
|
|
|
|
$object->inline_keyboard = [];
|
|
|
|
|
|
|
|
foreach($data as $item)
|
|
|
|
{
|
|
|
|
$object->inline_keyboard[] = InlineKeyboardButton::fromArray($item);
|
|
|
|
}
|
|
|
|
|
2023-02-13 13:57:03 -05:00
|
|
|
return $object;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|