1 | <?php |
||
30 | class Keyboard extends Entity |
||
31 | { |
||
32 | /** |
||
33 | * {@inheritdoc} |
||
34 | */ |
||
35 | 18 | public function __construct($data = []) |
|
43 | |||
44 | /** |
||
45 | * If this keyboard is an inline keyboard. |
||
46 | * |
||
47 | * @return bool |
||
48 | */ |
||
49 | 18 | public function isInlineKeyboard() |
|
53 | |||
54 | /** |
||
55 | * Get the proper keyboard button class for this keyboard. |
||
56 | * |
||
57 | * @return KeyboardButton|InlineKeyboardButton |
||
58 | */ |
||
59 | 12 | public function getKeyboardButtonClass() |
|
63 | |||
64 | /** |
||
65 | * Get the type of keyboard, either "inline_keyboard" or "keyboard". |
||
66 | * |
||
67 | * @return string |
||
68 | */ |
||
69 | 18 | public function getKeyboardType() |
|
73 | |||
74 | /** |
||
75 | * If no explicit keyboard is passed, try to create one from the parameters. |
||
76 | * |
||
77 | * @return array |
||
78 | */ |
||
79 | 18 | protected function createFromParams() |
|
116 | |||
117 | /** |
||
118 | * Create a new row in keyboard and add buttons. |
||
119 | * |
||
120 | * @return $this |
||
121 | */ |
||
122 | 2 | public function addRow() |
|
130 | |||
131 | /** |
||
132 | * Parse a given row to the correct array format. |
||
133 | * |
||
134 | * @param array $row |
||
135 | * |
||
136 | * @return array |
||
137 | */ |
||
138 | 15 | protected function parseRow($row) |
|
153 | |||
154 | /** |
||
155 | * Parse a given button to the correct KeyboardButton object type. |
||
156 | * |
||
157 | * @param array|string|\Longman\TelegramBot\Entities\KeyboardButton $button |
||
158 | * |
||
159 | * @return \Longman\TelegramBot\Entities\KeyboardButton|null |
||
160 | */ |
||
161 | 12 | protected function parseButton($button) |
|
162 | { |
||
163 | 12 | $button_class = $this->getKeyboardButtonClass(); |
|
164 | |||
165 | 12 | if ($button instanceof $button_class) { |
|
166 | 6 | return $button; |
|
167 | } |
||
168 | |||
169 | 6 | if (!$this->isInlineKeyboard() || $button_class::couldBe($button)) { |
|
170 | 6 | return new $button_class($button); |
|
171 | } |
||
172 | |||
173 | return null; |
||
174 | } |
||
175 | |||
176 | /** |
||
177 | * {@inheritdoc} |
||
178 | */ |
||
179 | 18 | protected function validate() |
|
196 | |||
197 | /** |
||
198 | * Remove the current custom keyboard and display the default letter-keyboard. |
||
199 | * |
||
200 | * @link https://core.telegram.org/bots/api/#replykeyboardremove |
||
201 | * |
||
202 | * @param array $data |
||
203 | * |
||
204 | * @return \Longman\TelegramBot\Entities\Keyboard |
||
205 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
206 | */ |
||
207 | 1 | public static function remove(array $data = []) |
|
208 | { |
||
209 | 1 | return new static(array_merge(['keyboard' => [], 'remove_keyboard' => true, 'selective' => false], $data)); |
|
210 | } |
||
211 | |||
212 | /** |
||
213 | * Display a reply interface to the user (act as if the user has selected the bot's message and tapped 'Reply'). |
||
214 | * |
||
215 | * @link https://core.telegram.org/bots/api#forcereply |
||
216 | * |
||
217 | * @param array $data |
||
218 | * |
||
219 | * @return \Longman\TelegramBot\Entities\Keyboard |
||
220 | * @throws \Longman\TelegramBot\Exception\TelegramException |
||
221 | */ |
||
222 | 1 | public static function forceReply(array $data = []) |
|
226 | } |
||
227 |