$message, 'status' => $status ); } /** * create a short string based on a integer * * @see https://www.jwz.org/base64-shortlinks/ * @return string */ static function b64sl_pack_id(string $id): string { $id = intval($id); $ida = ($id > 0xFFFFFFFF ? $id >> 32 : 0); // 32 bit big endian, top $idb = ($id & 0xFFFFFFFF); // 32 bit big endian, bottom $id = pack ('N', $ida) . pack ('N', $idb); $id = preg_replace('/^\000+/', '', "$id"); // omit high-order NUL bytes $id = base64_encode ($id); $id = str_replace ('+', '-', $id); // encode URL-unsafe "+" "/" $id = str_replace ('/', '_', $id); $id = preg_replace ('/=+$/', '', $id); // omit trailing padding bytes return $id; } /** * Decode a base64-encoded big-endian integer of up to 64 bits. * * @see https://www.jwz.org/base64-shortlinks/ * @param string $id * @return int */ static function b64sl_unpack_id(string $id): int { $id = str_replace ('-', '+', $id); // decode URL-unsafe "+" "/" $id = str_replace ('_', '/', $id); $id = base64_decode ($id); while (strlen($id) < 8) { $id = "\000$id"; } // pad with leading NULs $a = unpack ('N*', $id); // 32 bit big endian $id = ($a[1] << 32) | $a[2]; // pack top and bottom word return $id; } /** * create based on the given string a path * each char in string is a dir * asdef -> a/s/d/e/f/ * * @param string $string * @return string */ static function forwardslashStringToPath(string $string): string { $ret = ''; if(!empty($string)) { for ($i = 0; $i < strlen($string); $i++) { $ret .= $string[$i] . "/"; } } return $ret; } /** * Make the input more safe for logging * * @param mixed $input The array/string to be made more safe * @return string */ static function cleanForLog(mixed $input): mixed { $input = var_export($input, true); $input = preg_replace( "/[\t\n\r]/", " ", $input); return addcslashes($input, "\000..\037\177..\377\\"); } /** * error_log with a dedicated destination * Uses LOGFILE const * * @param string $msg The string to be written to the log */ static function sysLog(string $msg): void { error_log(date("c")." ".$msg."\n", 3, ERROR_LOG_FILE); } /** * error_log with a dedicated destination * Uses CREATE_LOG const * * @param string $msg * @return void */ static function createLog(string $msg): void { error_log(date("c")." ".$msg."\n", 3, CREATE_LOG); } }