Rev 1086 | Rev 1140 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1086 | Rev 1116 | ||
---|---|---|---|
Line 23... | Line 23... | ||
23 | \defined('INSIDE_OIDPLUS') or die; |
23 | \defined('INSIDE_OIDPLUS') or die; |
24 | // phpcs:enable PSR1.Files.SideEffects |
24 | // phpcs:enable PSR1.Files.SideEffects |
25 | 25 | ||
26 | class OIDplusLogger extends OIDplusBaseClass { |
26 | class OIDplusLogger extends OIDplusBaseClass { |
27 | 27 | ||
28 | private static function split_maskcodes($maskcodes) { |
- | |
- | 28 | /** |
|
29 | // This function splits a mask code containing multiple components |
29 | * This function splits a mask code containing multiple components |
30 | // (delimited by '+' or '/') in single components |
30 | * (delimited by '+' or '/') in single components |
31 | // It takes care that '+' and '/' inside brackets won't be used to split the codes |
31 | * It takes care that '+' and '/' inside brackets won't be used to split the codes |
32 | // Also, brackets can be escaped. |
32 | * Also, brackets can be escaped. |
33 | // The severity block (optional, must be standing in front of a component) |
33 | * The severity block (optional, must be standing in front of a component) |
34 | // is handled too. Inside the severity block, you may only use '/' to split components. |
34 | * is handled too. Inside the severity block, you may only use '/' to split components. |
35 | // The severity block will be implicitly repeated from the previous components if a component |
35 | * The severity block will be implicitly repeated from the previous components if a component |
36 | // does not feature one. |
36 | * does not feature one. |
37 | // |
37 | * |
38 | // "[S]AAA(BBB)+CCC(DDD)" ==> array( |
38 | * "[S]AAA(BBB)+CCC(DDD)" ==> array( |
39 | // array(array("S"),"AAA(BBB)"), |
39 | * array(array("S"),"AAA(BBB)"), |
40 | // array(array("S"),"CCC(DDD)") |
40 | * array(array("S"),"CCC(DDD)") |
41 | // ) |
41 | * ) |
42 | // "[S]AAA(B+BB)+CCC(DDD)" ==> array( |
42 | * "[S]AAA(B+BB)+CCC(DDD)" ==> array( |
43 | // array(array("S"),"AAA(B+BB)"), |
43 | * array(array("S"),"AAA(B+BB)"), |
44 | // array(array("S"),"CCC(DDD)") |
44 | * array(array("S"),"CCC(DDD)") |
45 | // ) |
45 | * ) |
46 | // "[S]AAA(B\)BB)+CCC(DDD)" ==> array( |
46 | * "[S]AAA(B\)BB)+CCC(DDD)" ==> array( |
47 | // array(array("S"),"AAA(B\)BB)"), |
47 | * array(array("S"),"AAA(B\)BB)"), |
48 | // array(array("S"),"CCC(DDD)") |
48 | * array(array("S"),"CCC(DDD)") |
49 | // ) |
49 | * ) |
- | 50 | * @param string $maskcodes |
|
- | 51 | * @return array|false |
|
50 | 52 | */ |
|
- | 53 | private static function split_maskcodes(string $maskcodes) { |
|
51 | $out = array(); |
54 | $out = array(); |
52 | $sevs = array(); // Note: The severity block will repeat for the next components if not changed explicitly |
55 | $sevs = array(); // Note: The severity block will repeat for the next components if not changed explicitly |
53 | 56 | ||
54 | $code = ''; |
57 | $code = ''; |
55 | $sev = ''; |
58 | $sev = ''; |
Line 168... | Line 171... | ||
168 | return $out; |
171 | return $out; |
169 | } |
172 | } |
170 | 173 | ||
171 | private static $missing_plugin_queue = array(); |
174 | private static $missing_plugin_queue = array(); |
172 | 175 | ||
- | 176 | /** |
|
- | 177 | * @return bool |
|
- | 178 | * @throws OIDplusException |
|
- | 179 | */ |
|
173 | public static function reLogMissing() { |
180 | public static function reLogMissing(): bool { |
174 | while (count(self::$missing_plugin_queue) > 0) { |
181 | while (count(self::$missing_plugin_queue) > 0) { |
175 | $item = self::$missing_plugin_queue[0]; |
182 | $item = self::$missing_plugin_queue[0]; |
176 | if (!self::log_internal($item[0], $item[1], false)) return false; |
183 | if (!self::log_internal($item[0], $item[1], false)) return false; |
177 | array_shift(self::$missing_plugin_queue); |
184 | array_shift(self::$missing_plugin_queue); |
178 | } |
185 | } |
179 | return true; |
186 | return true; |
180 | } |
187 | } |
181 | 188 | ||
- | 189 | /** |
|
- | 190 | * @param string $maskcodes |
|
- | 191 | * @param string $event |
|
- | 192 | * @return bool |
|
- | 193 | * @throws OIDplusException |
|
- | 194 | */ |
|
182 | public static function log($maskcodes, $event) { |
195 | public static function log(string $maskcodes, string $event): bool { |
183 | self::reLogMissing(); // try to re-log failed requests |
196 | self::reLogMissing(); // try to re-log failed requests |
184 | return self::log_internal($maskcodes, $event, true); |
197 | return self::log_internal($maskcodes, $event, true); |
185 | } |
198 | } |
186 | 199 | ||
- | 200 | /** |
|
- | 201 | * @param string $maskcodes |
|
- | 202 | * @param string $event |
|
- | 203 | * @param bool $allow_delayed_log |
|
- | 204 | * @return bool |
|
- | 205 | * @throws OIDplusException |
|
- | 206 | */ |
|
187 | private static function log_internal($maskcodes, $event, $allow_delayed_log) { |
207 | private static function log_internal(string $maskcodes, string $event, bool $allow_delayed_log): bool { |
188 | $loggerPlugins = OIDplus::getLoggerPlugins(); |
208 | $loggerPlugins = OIDplus::getLoggerPlugins(); |
189 | if (count($loggerPlugins) == 0) { |
209 | if (count($loggerPlugins) == 0) { |
190 | // The plugin might not be initialized in OIDplus::init() |
210 | // The plugin might not be initialized in OIDplus::init() |
191 | // yet. Remember the log entries for later submission during |
211 | // yet. Remember the log entries for later submission during |
192 | // OIDplus::init(); |
212 | // OIDplus::init(); |
Line 203... | Line 223... | ||
203 | // "Person 'X' moves from house 'A' to house 'B'" |
223 | // "Person 'X' moves from house 'A' to house 'B'" |
204 | // This event would affect the person X and the two houses, |
224 | // This event would affect the person X and the two houses, |
205 | // so, instead of logging into 3 logbooks separately, |
225 | // so, instead of logging into 3 logbooks separately, |
206 | // you would create a mask code that tells the system |
226 | // you would create a mask code that tells the system |
207 | // to put the message into the logbooks of person X, |
227 | // to put the message into the logbooks of person X, |
208 | // house A and house B. |
228 | // house A, and house B. |
209 | 229 | ||
210 | $users = array(); |
230 | $users = array(); |
211 | $objects = array(); |
231 | $objects = array(); |
212 | 232 | ||
213 | // A mask code with multiple components is split into single codes |
233 | // A mask code with multiple components is split into single codes |