1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Smoqadam\Keyboard; |
4
|
|
|
|
5
|
|
|
class Inline { |
6
|
|
|
|
7
|
|
|
public |
8
|
|
|
$inline_keyboard = []; |
|
|
|
|
9
|
|
|
|
10
|
|
|
private |
11
|
|
|
$current_row = 0; |
|
|
|
|
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Create new row. |
15
|
|
|
* |
16
|
|
|
* @return object |
17
|
|
|
*/ |
18
|
|
|
public function addRow(){ |
19
|
|
|
$this->current_row++; |
20
|
|
|
|
21
|
|
|
return $this; |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Add new button to current row. |
26
|
|
|
* |
27
|
|
|
* @param string $text Label text on the button |
28
|
|
|
* @param string $url Optional. HTTP url to be opened when button is pressed |
29
|
|
|
* @param string $callback_data Optional. Data to be sent in a callback query to the bot when button is pressed, 1-64 bytes |
30
|
|
|
* @param string $switch_inline_query Optional. If set, pressing the button will prompt the user to select one of their chats, open that chat and insert the bot‘s username and the specified inline query in the input field. Can be empty, in which case just the bot’s username will be inserted. |
31
|
|
|
* @param string $switch_inline_query_current_chat Optional. If set, pressing the button will insert the bot‘s username and the specified inline query in the current chat's input field. Can be empty, in which case only the bot’s username will be inserted. |
32
|
|
|
* @param string $callback_game Optional. Description of the game that will be launched when the user presses the button. NOTE: This type of button must always be the first button in the first row. |
33
|
|
|
* @return object |
34
|
|
|
*/ |
35
|
|
|
public function addButton(string $text, string $url = '', string $callback_data = '', string $switch_inline_query = '', string $switch_inline_query_current_chat = '', string $callback_game = ''){ |
36
|
|
|
$btn['text'] = $text; |
|
|
|
|
37
|
|
|
if($url != '') |
38
|
|
|
$btn['url'] = $url; |
39
|
|
|
elseif($callback_data != '') |
40
|
|
|
$btn['callback_data'] = $callback_data; |
41
|
|
|
elseif($switch_inline_query != '') |
42
|
|
|
$btn['switch_inline_query'] = $switch_inline_query; |
43
|
|
|
elseif($switch_inline_query_current_chat != '') |
44
|
|
|
$btn['switch_inline_query_current_chat'] = $switch_inline_query_current_chat; |
45
|
|
|
elseif($callback_game != '') |
46
|
|
|
$btn['callback_game'] = $callback_game; |
47
|
|
|
else |
48
|
|
|
$btn['callback_data'] = $text; |
49
|
|
|
|
50
|
|
|
$this->inline_keyboard[$this->current_row][] = $btn; |
51
|
|
|
|
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
} |
56
|
|
|
|
The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using
the property is implicitly global.
To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.