1 | <?php declare(strict_types = 1); |
||
13 | class Params |
||
14 | { |
||
15 | /** |
||
16 | * @var array List of valid script parameters. |
||
17 | */ |
||
18 | private static $valid_script_params = [ |
||
19 | 's', |
||
20 | 'a', |
||
21 | 'l', |
||
22 | 'i', |
||
23 | ]; |
||
24 | |||
25 | /** |
||
26 | * @var array List of vital parameters that must be passed. |
||
27 | */ |
||
28 | private static $valid_vital_bot_params = [ |
||
29 | 'api_key', |
||
30 | 'botname', |
||
31 | 'secret', |
||
32 | ]; |
||
33 | |||
34 | /** |
||
35 | * @var array List of valid extra parameters that can be passed. |
||
36 | */ |
||
37 | private static $valid_extra_bot_params = [ |
||
38 | 'webhook', |
||
39 | 'selfcrt', |
||
40 | 'logging', |
||
41 | 'admins', |
||
42 | 'mysql', |
||
43 | 'download_path', |
||
44 | 'upload_path', |
||
45 | 'commands_paths', |
||
46 | 'command_configs', |
||
47 | 'botan_token', |
||
48 | 'custom_input', |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * @var array List of all params passed to the script. |
||
53 | */ |
||
54 | private $script_params = []; |
||
55 | |||
56 | /** |
||
57 | * @var array List of all params passed at construction. |
||
58 | */ |
||
59 | private $bot_params = []; |
||
60 | |||
61 | /** |
||
62 | * Params constructor. |
||
63 | * |
||
64 | * api_key (string) Telegram Bot API key |
||
65 | * botname (string) Telegram Bot name |
||
66 | * secret (string) Secret string to validate calls |
||
67 | * webhook (string) URI of the webhook |
||
68 | * selfcrt (string) Path to the self-signed certificate |
||
69 | * logging (array) Array of logger files to set. |
||
70 | * admins (array) List of admins to enable. |
||
71 | * mysql (array) MySQL credentials to use. |
||
72 | * download_path (string) Custom download path to set. |
||
73 | * upload_path (string) Custom upload path to set. |
||
74 | * commands_paths (array) Custom commands paths to set. |
||
75 | * command_configs (array) List of custom command configs. |
||
76 | * botan_token (string) Botan token to enable botan.io support. |
||
77 | * custom_input (string) Custom raw JSON string to use as input. |
||
78 | * |
||
79 | * @param array $params All params to set the bot up with. |
||
80 | * |
||
81 | * @throws \InvalidArgumentException |
||
82 | */ |
||
83 | public function __construct(array $params) |
||
88 | |||
89 | /** |
||
90 | * Validate and set up the vital and extra params. |
||
91 | * |
||
92 | * @param $params |
||
93 | * |
||
94 | * @return \NPM\TelegramBotManager\Params |
||
95 | * @throws \InvalidArgumentException |
||
96 | */ |
||
97 | private function validateAndSetBotParams($params): self |
||
119 | |||
120 | /** |
||
121 | * Handle all script params, via web server handler or CLI. |
||
122 | * |
||
123 | * https://url/entry.php?s=<secret>&a=<action>&l=<loop> |
||
124 | * $ php entry.php s=<secret> a=<action> l=<loop> |
||
125 | * |
||
126 | * @return \NPM\TelegramBotManager\Params |
||
127 | */ |
||
128 | private function validateAndSetScriptParams(): self |
||
150 | |||
151 | /** |
||
152 | * Get a specific bot param. |
||
153 | * |
||
154 | * @param string $param |
||
155 | * |
||
156 | * @return mixed |
||
157 | */ |
||
158 | public function getBotParam(string $param) |
||
162 | |||
163 | /** |
||
164 | * Get an array of all bot params. |
||
165 | * |
||
166 | * @return array |
||
167 | */ |
||
168 | public function getBotParams(): array |
||
172 | |||
173 | /** |
||
174 | * Get a specific script param. |
||
175 | * |
||
176 | * @param string $param |
||
177 | * |
||
178 | * @return mixed |
||
179 | */ |
||
180 | public function getScriptParam(string $param) |
||
184 | |||
185 | /** |
||
186 | * Get an array of all script params. |
||
187 | * |
||
188 | * @return array |
||
189 | */ |
||
190 | public function getScriptParams(): array |
||
194 | } |
||
195 |