1 | <?php |
||
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 | ]; |
||
23 | |||
24 | /** |
||
25 | * @var array List of vital parameters that must be passed. |
||
26 | */ |
||
27 | private static $valid_vital_bot_params = [ |
||
28 | 'api_key', |
||
29 | 'botname', |
||
30 | 'secret', |
||
31 | ]; |
||
32 | |||
33 | /** |
||
34 | * @var array List of valid extra parameters that can be passed. |
||
35 | */ |
||
36 | private static $valid_extra_bot_params = [ |
||
37 | 'webhook', |
||
38 | 'selfcrt', |
||
39 | 'logging', |
||
40 | 'admins', |
||
41 | 'mysql', |
||
42 | 'download_path', |
||
43 | 'upload_path', |
||
44 | 'commands_paths', |
||
45 | 'command_configs', |
||
46 | 'botan_token', |
||
47 | 'custom_input', |
||
48 | ]; |
||
49 | |||
50 | /** |
||
51 | * @var array List of all params passed to the script. |
||
52 | */ |
||
53 | private $script_params = []; |
||
54 | |||
55 | /** |
||
56 | * @var array List of all params passed at construction. |
||
57 | */ |
||
58 | private $bot_params = []; |
||
59 | |||
60 | /** |
||
61 | * Params constructor. |
||
62 | * |
||
63 | * api_key (string) Telegram Bot API key |
||
64 | * botname (string) Telegram Bot name |
||
65 | * secret (string) Secret string to validate calls |
||
66 | * webhook (string) URI of the webhook |
||
67 | * selfcrt (string) Path to the self-signed certificate |
||
68 | * logging (array) Array of logger files to set. |
||
69 | * admins (array) List of admins to enable. |
||
70 | * mysql (array) MySQL credentials to use. |
||
71 | * download_path (string) Custom download path to set. |
||
72 | * upload_path (string) Custom upload path to set. |
||
73 | * commands_paths (array) Custom commands paths to set. |
||
74 | * command_configs (array) List of custom command configs. |
||
75 | * botan_token (string) Botan token to enable botan.io support. |
||
76 | * custom_input (string) Custom raw JSON string to use as input. |
||
77 | * |
||
78 | * @param array $params All params to set the bot up with. |
||
79 | * |
||
80 | * @throws \InvalidArgumentException |
||
81 | */ |
||
82 | public function __construct(array $params) |
||
87 | |||
88 | /** |
||
89 | * Validate and set up the vital and extra params. |
||
90 | * |
||
91 | * @param $params |
||
92 | * |
||
93 | * @throws \InvalidArgumentException |
||
94 | */ |
||
95 | private function validateAndSetBotParams($params) |
||
115 | |||
116 | /** |
||
117 | * Handle all script params, via web server handler or CLI. |
||
118 | * |
||
119 | * https://url/entry.php?s=<secret>&a=<action>&l=<loop> |
||
120 | * $ php entry.php s=<secret> a=<action> l=<loop> |
||
121 | */ |
||
122 | private function validateAndSetScriptParams() |
||
143 | |||
144 | /** |
||
145 | * Get a specific bot param. |
||
146 | * |
||
147 | * @param string $param |
||
148 | * |
||
149 | * @return mixed |
||
150 | */ |
||
151 | public function getBotParam($param) |
||
155 | |||
156 | public function getBotParams() |
||
160 | |||
161 | /** |
||
162 | * Get a specific script param. |
||
163 | * |
||
164 | * @param string $param |
||
165 | * |
||
166 | * @return mixed |
||
167 | */ |
||
168 | public function getScriptParam($param) |
||
172 | |||
173 | public function getScriptParams() |
||
177 | } |
||
178 |