>|null the configuration */ static function read_config(): ?array { // TODO: Check permissions, return `null` if too permissive $config = parse_ini_file("config.default.ini.php", process_sections: true, scanner_mode: INI_SCANNER_TYPED); if ($config === false) return null; if (file_exists("config.ini.php")) { $config_custom = parse_ini_file("config.ini.php", process_sections: true, scanner_mode: INI_SCANNER_TYPED); if ($config_custom === false) return null; $config = array_replace_recursive($config, $config_custom); } return $config; } /** * Creates the main logger instance. * * @param array $logger_config the logger section of the configuration * @return Logger the main logger instance */ static function create_logger(array $logger_config): Logger { $logger = new Logger("main"); $logger->pushHandler(new StreamHandler($logger_config["file"], $logger_config["level"])); ErrorHandler::register($logger); return $logger; } /** * Parses POST values from JSON-based inputs. * * @return array|null the parsed POST-ed values */ static function parse_post(): ?array { $output = $_POST; $post_input = file_get_contents("php://input"); if ($post_input !== false) $output = json_decode($post_input, associative: true); return $output; } /** * Generates an appropriate CSRF token. * * @return string the generated CSRF token * @throws Exception if the CSRF token could not be generated */ static function generate_csrf_token(): string { return bin2hex(random_bytes(32)); } }