1 | <?php |
||
26 | trait CommandHandler |
||
27 | { |
||
28 | /** |
||
29 | * \addtogroup Commands |
||
30 | * \brief Bots command and usage. |
||
31 | * @{ |
||
32 | */ |
||
33 | |||
34 | /** @internal |
||
35 | * \brief Contains all command used by the bot. */ |
||
36 | private $_commands = []; |
||
37 | |||
38 | /** |
||
39 | * @internal |
||
40 | * \brief Initialize commands to speed up processing. |
||
41 | * \details Get all command that the bot handle, and put them in priority. |
||
42 | */ |
||
43 | 3 | protected function initCommands() |
|
60 | |||
61 | /** |
||
62 | * @internal |
||
63 | * \brief Process updates prioritizing bot's commands over the general methods (e.g. BaseBot::processMessage()) |
||
64 | * @param array $update Update to process. |
||
65 | * @return bool True if this update trigger any command. |
||
66 | */ |
||
67 | 5 | protected function processCommands(array $update) : bool |
|
86 | |||
87 | /** |
||
88 | * \brief Add a command to the bot. |
||
89 | * @param BasicCommand $command Command to add. Must be an object that inherits BasicCommand class. |
||
90 | */ |
||
91 | 2 | public function addCommand(BasicCommand $command) |
|
95 | |||
96 | /** |
||
97 | * \brief Add various commands at once. |
||
98 | * @param ...BasicCommand $commands The commands to add. |
||
99 | */ |
||
100 | 1 | public function addCommands(BasicCommand ...$commands) |
|
106 | |||
107 | /** |
||
108 | * \brief Add a message command to the bot. |
||
109 | * @param string $command The command that will trigger the function (e.g. start). |
||
110 | * @param callable $script The function that will be triggered by a command. |
||
111 | */ |
||
112 | 1 | public function addMessageCommand(string $command, callable $script) |
|
116 | |||
117 | /** |
||
118 | * \brief Add a callback command to the bot. |
||
119 | * @param string $data The data that will trigger the function. |
||
120 | * @param callable $script The function that will be triggered by the data. |
||
121 | */ |
||
122 | public function addCallbackCommand(string $data, callable $script) |
||
126 | |||
127 | /** @} */ |
||
128 | } |
||
129 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.