get($key, $default, $type); } /**用户 * 配置写入 * @param string $key * @param mixed $value * @return void */ function setConf(string $key, mixed $value): void { Config::getInstance()->set($key, $value); } /** * 配置开关获取(大量调用独立抽取) * @param string $key * @param bool $default * @return bool */ function getEnable(string $key, bool $default = false): bool { return getConf($key . '.enable', $default, 'bool'); } /** * 获取用户相关信息(Login) * @param string $key * @return mixed */ function getU(string $key): mixed { $value = ''; $fillable = ['username', 'password', 'uid', 'csrf', 'cookie', 'access_token', 'refresh_token', 'sid', 'pc_cookie']; if (in_array($key, $fillable)) { $value = Cache::get('auth_' . $key, 'Login'); } return $value ?: ''; } /** * 设置用户相关信息(Login) * @param string $key * @param mixed $value * @return void */ function setU(string $key, mixed $value): void { $fillable = ['username', 'password', 'uid', 'csrf', 'cookie', 'access_token', 'refresh_token', 'sid', 'pc_cookie']; if (in_array($key, $fillable)) { Cache::set('auth_' . $key, $value, 'Login'); } } // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- /** * 获取APP名称 * @return string */ function getAppName(): string { return Env::getInstance()->app_name; } /** * 获取APP版本 * @return string */ function getAppVersion(): string { return Env::getInstance()->app_version; } /** * 获取APP主页 * @return string */ function getAppHomePage(): string { return Env::getInstance()->app_source; } // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- /** * 错误退出 * @param mixed $message * @param array $context * @param int $delay * @return void */ #[NoReturn] function failExit(mixed $message = 'exit', array $context = [], int $delay = 60 * 2): void { Log::error($message, $context); // 如果在docker环境中,延迟退出,方便查看错误 if (Env::isDocker()) { // 暂停两分钟后自动退出 sleep($delay); } else { // 其他环境暂停 sleep($delay / 4); } die(); } // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------- /** * 获取设备信息 * @param string $key * @param mixed|null $default * @param string $type * @return mixed */ function getDevice(string $key, mixed $default = null, string $type = 'default'): mixed { return Device::getInstance()->get($key, $default, $type); } ///** // * 缓存读取 // * @param string $key // * @param string $extra_name // * @return mixed // */ //function getCache(string $key, string $extra_name = ''): mixed //{ // return Cache::getInstance()->_get($key, $extra_name); //} // ///** // * 缓存写入 // * @param string $key // * @param $data // * @param string $extra_name // */ //function setCache(string $key, $data, string $extra_name = ''): void //{ // Cache::getInstance()->_set($key, $data, $extra_name); //} /** * @param string $dir * @param array $exclude * @return void */ function requireDir(string $dir, array $exclude = []): void { $handle = opendir($dir);//打开文件夹 while (false !== ($file = readdir($handle))) {//读取文件 if ($file != '.' && $file != '..') { if (in_array($file, $exclude)) continue; // $filepath = $dir . '/' . $file;//文件路径 if (filetype($filepath) == 'dir') {//如果是文件夹 requireDir($filepath);//继续读 } else { include_once($filepath);//引入文件 } } } }