1 | <?php |
||
7 | trait CallbackCommand { |
||
8 | |||
9 | /** |
||
10 | * \addtogroup Commands |
||
11 | * @{ |
||
12 | */ |
||
13 | |||
14 | /** \brief Store the command triggered on callback query. */ |
||
15 | protected $_callback_commands; |
||
16 | |||
17 | /** |
||
18 | * \brief Add a function that will be executed everytime a callback query contains a string as data |
||
19 | * \details Use this syntax: |
||
20 | * |
||
21 | * addMessageCommand("menu", function($bot, $callback_query) { |
||
22 | * $bot->editMessageText($callback_query['message']['message_id'], "This is the menu"); }); |
||
23 | * @param $data The string that will trigger this function. |
||
24 | * @param $script The function that will be triggered by the callback query if it contains the $data string. Must take an object(the bot) and an array(the callback query received). |
||
25 | */ |
||
26 | public function addCallbackCommand(string $data, callable $script) { |
||
34 | |||
35 | /** |
||
36 | * \brief (<i>Internal</i>) Process the callback query and check if it triggers a command of this type. |
||
37 | * @param $callback_query Callback query to process. |
||
38 | * @return True if the callback query triggered a command. |
||
39 | */ |
||
40 | protected function processCallbackCommand(array $callback_query) : bool { |
||
67 | |||
68 | /** @} */ |
||
69 | |||
70 | } |
||
71 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: