1 | <?php |
||
34 | trait User |
||
35 | { |
||
36 | /** @} */ |
||
37 | |||
38 | abstract protected function sanitizeUserTable(); |
||
39 | |||
40 | /** @internal |
||
41 | * \brief PDO connection to the database. */ |
||
42 | public $pdo; |
||
43 | |||
44 | /** |
||
45 | * \addtogroup Database |
||
46 | * @{ |
||
47 | */ |
||
48 | |||
49 | /** |
||
50 | * \addtogroup Users-handle Users handling |
||
51 | * \brief Handle bot users on the database. |
||
52 | * @{ |
||
53 | */ |
||
54 | |||
55 | /** \brief Table contaning bot users data in the SQL database. */ |
||
56 | public $user_table = 'User'; |
||
57 | |||
58 | /** \brief Name of the column that represents the user id in the sql database */ |
||
59 | public $id_column = 'chat_id'; |
||
60 | |||
61 | /** |
||
62 | * \brief Add a user to the database. |
||
63 | * \details Add a user to the database in Bot::$user_table table and Bot::$id_column column using Bot::$pdo connection. |
||
64 | * @param string|int $chat_id chat ID of the user to add. |
||
65 | * @return bool True on success. |
||
66 | */ |
||
67 | public function addUser($chat_id) : bool |
||
92 | |||
93 | /** |
||
94 | * \brief Send a message to every user available on the database. |
||
95 | * \details Send a message to all subscribed users, change Bot::$user_table and Bot::$id_column to match your database structure. |
||
96 | * This method requires Bot::$pdo connection set. |
||
97 | * All parameters are the same as CoreBot::sendMessage. |
||
98 | * Because a limitation of Telegram Bot API the bot will have a delay after 20 messages sent in different chats. |
||
99 | * @return int How many messages were sent. |
||
100 | * @see CoreBot::sendMessage |
||
101 | */ |
||
102 | public function broadcastMessage( |
||
136 | |||
137 | /** @} */ |
||
138 | |||
139 | /** @} */ |
||
140 | } |
||
141 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.