tgbotlib/src/TgBotLib/Objects/Telegram/InlineKeyboardMarkup.php

68 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/** @noinspection PhpMissingFieldTypeInspection */
2023-02-14 17:41:38 -05:00
namespace TgBotLib\Objects\Telegram;
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[][]
*/
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;
}
/**
* Constructs the object from an array representation
*
* @param array $data
2023-02-16 15:27:57 -05:00
* @return InlineKeyboardMarkup
*/
2023-02-16 15:27:57 -05:00
public static function fromArray(array $data): self
{
$object = new self();
2023-02-14 17:35:16 -05:00
$object->inline_keyboard = [];
foreach($data as $item)
{
$object->inline_keyboard[] = InlineKeyboardButton::fromArray($item);
}
return $object;
}
}