1 | <?php |
||
17 | class Config |
||
18 | { |
||
19 | use Property; |
||
20 | |||
21 | const DEFAULT_LIMIT = 1; |
||
22 | |||
23 | const DEFAULT_OFFSET = -1; |
||
24 | |||
25 | const REQUEST_TIMEOUT = 6; |
||
26 | |||
27 | const BOT_PREFIX = 'bot'; |
||
28 | |||
29 | const COMMAND_NAMESPACE_PATTERN = 'Teebot\\Bot\\%s\\Command'; |
||
30 | |||
31 | const EVENT_NAMESPACE_PATTERN = 'Teebot\\Bot\\%s\\EntityEvent'; |
||
32 | |||
33 | const CONFIG_FILENAME = 'config.php'; |
||
34 | |||
35 | const BOT_DIR_PATTERN = '%s/../Bot/%s'; |
||
36 | |||
37 | protected $name = null; |
||
38 | |||
39 | protected $token; |
||
40 | |||
41 | protected $url = 'https://api.telegram.org'; |
||
42 | |||
43 | protected $timeout = 1; |
||
44 | |||
45 | protected $method; |
||
46 | |||
47 | protected $file_url = 'https://api.telegram.org/file/bot'; |
||
48 | |||
49 | protected $log_file = null; |
||
50 | |||
51 | protected $events; |
||
52 | |||
53 | protected $command_on_first = true; |
||
54 | |||
55 | protected $commandNamespace = null; |
||
56 | |||
57 | protected $entityEventNamespace = null; |
||
58 | |||
59 | protected $botDir = null; |
||
60 | |||
61 | /** |
||
62 | * Constructs configuration object with either bot name or bot config file passed. |
||
63 | * |
||
64 | * @param string $botConfig Path to bot's configuration file |
||
65 | */ |
||
66 | public function __construct($botConfig = '') |
||
70 | |||
71 | /** |
||
72 | * Initialises bot configuration via bot name or configuration file. |
||
73 | * |
||
74 | * @param string $botConfig Path to bot's configuration file |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function initBotConfiguration($botConfig = '') |
||
93 | |||
94 | /** |
||
95 | * Loads configuration file in JSON format. |
||
96 | * |
||
97 | * @param string $configFile Path to configuration file |
||
98 | */ |
||
99 | protected function loadConfigFile($configFile) |
||
109 | |||
110 | /** |
||
111 | * Returns bot token string, if the value was not set in config - default value will be used |
||
112 | * |
||
113 | * @return string |
||
114 | */ |
||
115 | public function getToken() |
||
119 | |||
120 | /** |
||
121 | * Returns Bot-API request url |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | public function getUrl() |
||
129 | |||
130 | /** |
||
131 | * Returns request timeout in seconds, if the value was not set in config - default value will be used |
||
132 | * |
||
133 | * @return int |
||
134 | */ |
||
135 | public function getTimeout() |
||
139 | |||
140 | /** |
||
141 | * Returns name of the bot if it was set |
||
142 | * |
||
143 | * @return null|string |
||
144 | */ |
||
145 | public function getName() |
||
149 | |||
150 | /** |
||
151 | * Returns request method name |
||
152 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getMethod() |
||
159 | |||
160 | /** |
||
161 | * Returns whether command should be searched on first position in text. |
||
162 | * |
||
163 | * @return boolean |
||
164 | */ |
||
165 | public function getCommandOnFirst() |
||
169 | |||
170 | /** |
||
171 | * Returns command's name space if bots are placed in default Bot directory |
||
172 | * |
||
173 | * @return string |
||
174 | */ |
||
175 | public function getCommandNamespace() |
||
179 | |||
180 | /** |
||
181 | * Returns entity's name space if bots are placed in default Bot directory |
||
182 | * |
||
183 | * @return string |
||
184 | */ |
||
185 | public function getEntityEventNamespace() |
||
189 | |||
190 | /** |
||
191 | * Returns base url from the files to download from Telegram's storage servers, if the value |
||
192 | * was not set in config - default value will be used |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function getFileUrl() |
||
200 | |||
201 | /** |
||
202 | * Returns path to log file for Errors, if not set - all errors will be echoed. |
||
203 | * |
||
204 | * @return null|string |
||
205 | */ |
||
206 | public function getLogFile() |
||
210 | |||
211 | /** |
||
212 | * Returns an array with defined events map, if not set default namespaces and mapping will be used. |
||
213 | * |
||
214 | * @return array |
||
215 | */ |
||
216 | public function getEvents() |
||
220 | |||
221 | /** |
||
222 | * Returns base url for the files to download from Telegram's storage servers, token will be also added. |
||
223 | * If the value of file url was not set in config - default value will be used |
||
224 | * |
||
225 | * @return null|string |
||
226 | */ |
||
227 | public function getFileBasePath() |
||
235 | } |
||
236 |