1 | <?php |
||
13 | class BotsManager |
||
14 | { |
||
15 | /** |
||
16 | * The config instance. |
||
17 | * |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $config; |
||
21 | |||
22 | /** |
||
23 | * The container instance. |
||
24 | * |
||
25 | * @var \Illuminate\Contracts\Container\Container |
||
26 | */ |
||
27 | protected $container; |
||
28 | |||
29 | /** |
||
30 | * The active bot instances. |
||
31 | * |
||
32 | * @var Api[] |
||
33 | */ |
||
34 | protected $bots = []; |
||
35 | |||
36 | /** |
||
37 | * TelegramManager constructor. |
||
38 | * |
||
39 | * @param array $config |
||
40 | */ |
||
41 | public function __construct($config) |
||
45 | |||
46 | /** |
||
47 | * Set the IoC Container. |
||
48 | * |
||
49 | * @param $container Container instance |
||
50 | * |
||
51 | * @return $this |
||
52 | */ |
||
53 | public function setContainer(Container $container) |
||
59 | |||
60 | /** |
||
61 | * Get the configuration for a bot. |
||
62 | * |
||
63 | * @param string|null $name |
||
64 | * |
||
65 | * @throws \InvalidArgumentException |
||
66 | * |
||
67 | * @return array |
||
68 | */ |
||
69 | public function getBotConfig($name = null) |
||
82 | |||
83 | /** |
||
84 | * Get a bot instance. |
||
85 | * |
||
86 | * @param string $name |
||
87 | * |
||
88 | * @return Api |
||
89 | */ |
||
90 | public function bot($name = null) |
||
100 | |||
101 | /** |
||
102 | * Reconnect to the given bot. |
||
103 | * |
||
104 | * @param string $name |
||
105 | * |
||
106 | * @return Api |
||
107 | */ |
||
108 | public function reconnect($name = null) |
||
115 | |||
116 | /** |
||
117 | * Disconnect from the given bot. |
||
118 | * |
||
119 | * @param string $name |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | public function disconnect($name = null) |
||
128 | |||
129 | /** |
||
130 | * Get the specified configuration value for Telegram. |
||
131 | * |
||
132 | * @param string $key |
||
133 | * @param mixed $default |
||
134 | * |
||
135 | * @return mixed |
||
136 | */ |
||
137 | public function getConfig($key, $default = null) |
||
141 | |||
142 | /** |
||
143 | * Get the default bot name. |
||
144 | * |
||
145 | * @return string |
||
146 | */ |
||
147 | public function getDefaultBot() |
||
151 | |||
152 | /** |
||
153 | * Set the default bot name. |
||
154 | * |
||
155 | * @param string $name |
||
156 | * |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function setDefaultBot($name) |
||
165 | |||
166 | /** |
||
167 | * Return all of the created bots. |
||
168 | * |
||
169 | * @return Api[] |
||
170 | */ |
||
171 | public function getBots() |
||
175 | |||
176 | /** |
||
177 | * De-duplicate an array. |
||
178 | * |
||
179 | * @param array $array |
||
180 | * |
||
181 | * @return array |
||
182 | */ |
||
183 | protected function deduplicateArray(array $array) |
||
187 | |||
188 | /** |
||
189 | * Make the bot instance. |
||
190 | * |
||
191 | * @param string $name |
||
192 | * |
||
193 | * @return Api |
||
194 | */ |
||
195 | protected function makeBot($name) |
||
220 | |||
221 | /** |
||
222 | * Builds the list of commands for the given commands array. |
||
223 | * |
||
224 | * @param array $commands |
||
225 | * |
||
226 | * @return array An array of commands which includes global and bot specific commands. |
||
227 | */ |
||
228 | protected function parseBotCommands(array $commands) |
||
235 | |||
236 | /** |
||
237 | * Parse an array of commands and build a list. |
||
238 | * |
||
239 | * @param array $commands |
||
240 | * |
||
241 | * @return array |
||
242 | */ |
||
243 | protected function parseCommands(array $commands) |
||
278 | |||
279 | /** |
||
280 | * Magically pass methods to the default bot. |
||
281 | * |
||
282 | * @param string $method |
||
283 | * @param array $parameters |
||
284 | * |
||
285 | * @return mixed |
||
286 | */ |
||
287 | public function __call($method, $parameters) |
||
291 | } |
||
292 |
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: