1 | <?php declare(strict_types=1); |
||
15 | class Params |
||
16 | { |
||
17 | /** |
||
18 | * @var array List of valid script parameters. |
||
19 | */ |
||
20 | private static $valid_script_params = [ |
||
21 | 's', // secret |
||
22 | 'a', // action |
||
23 | 'l', // loop |
||
24 | 'i', // interval |
||
25 | 'g', // group (for cron) |
||
26 | ]; |
||
27 | |||
28 | /** |
||
29 | * @var array List of vital parameters that must be passed. |
||
30 | */ |
||
31 | private static $valid_vital_bot_params = [ |
||
32 | 'api_key', |
||
33 | ]; |
||
34 | |||
35 | /** |
||
36 | * @var array List of valid extra parameters that can be passed. |
||
37 | */ |
||
38 | private static $valid_extra_bot_params = [ |
||
39 | 'bot_username', |
||
40 | 'secret', |
||
41 | 'validate_request', |
||
42 | 'valid_ips', |
||
43 | 'webhook', |
||
44 | 'logging', |
||
45 | 'limiter', |
||
46 | 'admins', |
||
47 | 'mysql', |
||
48 | 'paths', |
||
49 | 'commands', |
||
50 | 'botan', |
||
51 | 'cron', |
||
52 | 'custom_input', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @var array List of all params passed to the script. |
||
57 | */ |
||
58 | private $script_params = []; |
||
59 | |||
60 | /** |
||
61 | * @var array List of all params passed at construction, predefined with defaults. |
||
62 | */ |
||
63 | private $bot_params = [ |
||
64 | 'validate_request' => true, |
||
65 | ]; |
||
66 | |||
67 | /** |
||
68 | * Params constructor. |
||
69 | * |
||
70 | * api_key (string) Telegram Bot API key |
||
71 | * bot_username (string) Telegram Bot username |
||
72 | * secret (string) Secret string to validate calls |
||
73 | * validate_request (bool) Only allow webhook access from valid Telegram API IPs and defined valid_ips |
||
74 | * valid_ips (array) Any IPs, besides Telegram API IPs, that are allowed to access the webhook |
||
75 | * webhook (array) |
||
76 | * - url (string) URI of the webhook |
||
77 | * - certificate (string) Path to the self-signed certificate |
||
78 | * - max_connections (int) Maximum allowed simultaneous HTTPS connections to the webhook |
||
79 | * - allowed_updates (array) List the types of updates you want your bot to receive |
||
80 | * logging (array) Array of logger files to set. |
||
81 | * limiter (array) |
||
82 | * - enabled (bool) Set limiter. |
||
83 | * - options (array) Limiter options. |
||
84 | * admins (array) List of admins to enable. |
||
85 | * mysql (array) MySQL credentials to use. |
||
86 | * paths (array) |
||
87 | * - download (string) Custom download path to set. |
||
88 | * - upload (string) Custom upload path to set. |
||
89 | * commands (array) |
||
90 | * - paths (array) Custom commands paths to set. |
||
91 | * - configs (array) List of custom command configs. |
||
92 | * botan (array) |
||
93 | * - token (string) Botan token to enable botan.io support. |
||
94 | * - options (array) Botan options. |
||
95 | * custom_input (string) Custom raw JSON string to use as input. |
||
96 | * cron (array) |
||
97 | * - groups (array) Groups of cron commands to run. |
||
98 | * - default (array) Default group of cron commands. |
||
99 | * |
||
100 | * @param array $params All params to set the bot up with. |
||
101 | * |
||
102 | * @throws \TelegramBot\TelegramBotManager\Exception\InvalidParamsException |
||
103 | */ |
||
104 | public function __construct(array $params) |
||
109 | |||
110 | /** |
||
111 | * Validate and set up the vital and extra params. |
||
112 | * |
||
113 | * @param $params |
||
114 | * |
||
115 | * @return \TelegramBot\TelegramBotManager\Params |
||
116 | * @throws \TelegramBot\TelegramBotManager\Exception\InvalidParamsException |
||
117 | */ |
||
118 | private function validateAndSetBotParams($params): self |
||
145 | |||
146 | /** |
||
147 | * Handle all script params, via web server handler or CLI. |
||
148 | * |
||
149 | * https://url/entry.php?s=<secret>&a=<action>&l=<loop> |
||
150 | * $ php entry.php s=<secret> a=<action> l=<loop> |
||
151 | * |
||
152 | * @return \TelegramBot\TelegramBotManager\Params |
||
153 | */ |
||
154 | private function validateAndSetScriptParams(): self |
||
178 | |||
179 | /** |
||
180 | * Get a specific bot param, allowing array-dot notation. |
||
181 | * |
||
182 | * @param string $param |
||
183 | * @param mixed $default |
||
184 | * |
||
185 | * @return mixed |
||
186 | */ |
||
187 | public function getBotParam(string $param, $default = null) |
||
201 | |||
202 | /** |
||
203 | * Get an array of all bot params. |
||
204 | * |
||
205 | * @return array |
||
206 | */ |
||
207 | public function getBotParams(): array |
||
211 | |||
212 | /** |
||
213 | * Get a specific script param. |
||
214 | * |
||
215 | * @param string $param |
||
216 | * @param mixed $default |
||
217 | * |
||
218 | * @return mixed |
||
219 | */ |
||
220 | public function getScriptParam(string $param, $default = null) |
||
224 | |||
225 | /** |
||
226 | * Get an array of all script params. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | public function getScriptParams(): array |
||
234 | } |
||
235 |