1 | <?php |
||
14 | class BotsManager |
||
15 | { |
||
16 | /** |
||
17 | * The config instance. |
||
18 | * |
||
19 | * @var array |
||
20 | */ |
||
21 | protected $config; |
||
22 | |||
23 | /** |
||
24 | * The container instance. |
||
25 | * |
||
26 | * @var \Illuminate\Contracts\Container\Container |
||
27 | */ |
||
28 | protected $container; |
||
29 | |||
30 | /** |
||
31 | * The active bot instances. |
||
32 | * |
||
33 | * @var Api[] |
||
34 | */ |
||
35 | protected $bots = []; |
||
36 | |||
37 | /** |
||
38 | * TelegramManager constructor. |
||
39 | * |
||
40 | * @param array $config |
||
41 | */ |
||
42 | public function __construct(array $config) |
||
46 | |||
47 | /** |
||
48 | * Set the IoC Container. |
||
49 | * |
||
50 | * @param $container Container instance |
||
51 | * |
||
52 | * @return $this |
||
53 | */ |
||
54 | public function setContainer(Container $container) |
||
60 | |||
61 | /** |
||
62 | * Get the configuration for a bot. |
||
63 | * |
||
64 | * @param string|null $name |
||
65 | * |
||
66 | * @throws \InvalidArgumentException |
||
67 | * |
||
68 | * @return array |
||
69 | */ |
||
70 | public function getBotConfig($name = null) |
||
83 | |||
84 | /** |
||
85 | * Get a bot instance. |
||
86 | * |
||
87 | * @param string $name |
||
88 | * |
||
89 | * @return Api |
||
90 | */ |
||
91 | public function bot($name = null) |
||
101 | |||
102 | /** |
||
103 | * Reconnect to the given bot. |
||
104 | * |
||
105 | * @param string $name |
||
106 | * |
||
107 | * @return Api |
||
108 | */ |
||
109 | public function reconnect($name = null) |
||
116 | |||
117 | /** |
||
118 | * Disconnect from the given bot. |
||
119 | * |
||
120 | * @param string $name |
||
121 | * |
||
122 | * @return void |
||
123 | */ |
||
124 | public function disconnect($name = null) |
||
129 | |||
130 | /** |
||
131 | * Get the specified configuration value for Telegram. |
||
132 | * |
||
133 | * @param string $key |
||
134 | * @param mixed $default |
||
135 | * |
||
136 | * @return mixed |
||
137 | */ |
||
138 | public function getConfig($key, $default = null) |
||
142 | |||
143 | /** |
||
144 | * Get the default bot name. |
||
145 | * |
||
146 | * @return string |
||
147 | */ |
||
148 | public function getDefaultBot() |
||
152 | |||
153 | /** |
||
154 | * Set the default bot name. |
||
155 | * |
||
156 | * @param string $name |
||
157 | * |
||
158 | * @return $this |
||
159 | */ |
||
160 | public function setDefaultBot($name) |
||
166 | |||
167 | /** |
||
168 | * Return all of the created bots. |
||
169 | * |
||
170 | * @return Api[] |
||
171 | */ |
||
172 | public function getBots() |
||
176 | |||
177 | /** |
||
178 | * De-duplicate an array. |
||
179 | * |
||
180 | * @param array $array |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | protected function deduplicateArray(array $array) |
||
188 | |||
189 | /** |
||
190 | * Make the bot instance. |
||
191 | * |
||
192 | * @param string $name |
||
193 | * |
||
194 | * @return Api |
||
195 | */ |
||
196 | protected function makeBot($name) |
||
221 | |||
222 | /** |
||
223 | * Builds the list of commands for the given commands array. |
||
224 | * |
||
225 | * @param array $commands |
||
226 | * |
||
227 | * @return array An array of commands which includes global and bot specific commands. |
||
228 | */ |
||
229 | protected function parseBotCommands(array $commands) |
||
236 | |||
237 | /** |
||
238 | * Parse an array of commands and build a list. |
||
239 | * |
||
240 | * @param array $commands |
||
241 | * |
||
242 | * @return array |
||
243 | */ |
||
244 | protected function parseCommands(array $commands) |
||
279 | |||
280 | /** |
||
281 | * Magically pass methods to the default bot. |
||
282 | * |
||
283 | * @param string $method |
||
284 | * @param array $parameters |
||
285 | * |
||
286 | * @return mixed |
||
287 | */ |
||
288 | public function __call($method, $parameters) |
||
292 | } |
||
293 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: