loadResource($filename, 'json'); // $this->app_name = $this->resource->get('project', 'BiliHelper-personal'); $this->app_version = $this->resource->get('version', '0.0.0.000000'); $this->app_branch = $this->resource->get('branch', 'master'); $this->app_source = $this->resource->get('source', 'https://github.com/lkeme/BiliHelper-personal'); // $this->inspectConfigure()->inspectExtension(); } /** * @use 检查是否开启 * @return $this */ protected function inspectExtension(): Env { $default_extensions = ['curl', 'openssl', 'sockets', 'json', 'zlib', 'mbstring']; foreach ($default_extensions as $extension) { if (!extension_loaded($extension)) { Log::error("检查到项目依赖 $extension 扩展未加载。"); Log::error("请在 php.ini中启用 $extension 扩展后重试。"); Log::error("程序常见问题请移步 $this->app_source 文档部分查看。"); failExit(""); } } return $this; } /** * @use 检查php环境 * @return $this */ protected function inspectConfigure(): Env { Log::info("欢迎使用 项目: $this->app_name@$this->app_branch 版本: $this->app_version"); Log::info("使用说明请移步 $this->app_source 查看"); if (PHP_SAPI != 'cli') { failExit('Please run this script from command line .'); } if (version_compare(PHP_VERSION, '8.0.0', '<')) { failExit('Please upgrade PHP version < 8.0.0 .'); } return $this; } /** * @use 重写获取路径 * @param string $filename * @return string */ protected function getFilePath(string $filename): string { return str_replace("\\", "/", APP_RESOURCES_PATH . $filename); } /** * @use Check: running in docker? * @return bool */ public static function isDocker(): bool { // Win直接跳出 if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') { return false; } if (!file_exists('/.dockerenv')) { return false; } // 检查/proc/1/cgroup内是否包含"docker"等字符串; if (!is_file('/proc/self/cgroup') || !preg_match('%^\d+:\w+:/(docker|actions_job)/' . preg_quote(gethostname(), '%') . '\w+%sm', file_get_contents('/proc/self/cgroup'))) { return false; } // $processStack = explode(PHP_EOL, shell_exec('cat /proc/self/cgroup | grep docker')); // $processStack = array_filter($processStack); // return count($processStack) > 0; return true; } }