diff --git a/src/think/App.php b/src/think/App.php index f4dcc2f99b..123db4984f 100644 --- a/src/think/App.php +++ b/src/think/App.php @@ -173,7 +173,7 @@ class App extends Container */ public function __construct(string $rootPath = '') { - $this->thinkPath = realpath(dirname(__DIR__)) . DIRECTORY_SEPARATOR; + $this->thinkPath = dirname(__DIR__) . DIRECTORY_SEPARATOR; $this->rootPath = $rootPath ? rtrim($rootPath, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR : $this->getDefaultRootPath(); $this->appPath = $this->rootPath . 'app' . DIRECTORY_SEPARATOR; $this->runtimePath = $this->rootPath . 'runtime' . DIRECTORY_SEPARATOR; @@ -538,14 +538,14 @@ protected function load(): void $configPath = $this->getConfigPath(); - $files = []; - if (is_dir($configPath)) { - $files = glob($configPath . '*' . $this->configExt); - } + foreach (scandir($configPath) as $name) { + if (!str_ends_with($name, $this->configExt) || !is_file($configPath . $name)) { + continue; + } - foreach ($files as $file) { - $this->config->load($file, pathinfo($file, PATHINFO_FILENAME)); + $this->config->load($configPath . $name, pathinfo($name, PATHINFO_FILENAME)); + } } if (is_file($appPath . 'event.php')) { diff --git a/src/think/Http.php b/src/think/Http.php index 8af0805e35..ded021177a 100644 --- a/src/think/Http.php +++ b/src/think/Http.php @@ -1,4 +1,5 @@ getRoutePath(); if (is_dir($routePath)) { - $files = glob($routePath . '*.php'); - foreach ($files as $file) { - include $file; + foreach (scandir($routePath) as $name) { + if (!str_ends_with($name, '.php') || !is_file($routePath . $name)) { + continue; + } + + include $routePath . $name; } } diff --git a/src/think/Lang.php b/src/think/Lang.php index d62c98657e..f07b046bda 100644 --- a/src/think/Lang.php +++ b/src/think/Lang.php @@ -137,8 +137,22 @@ public function switchLangSet(string $langset) ]); // 加载系统语言包 - $files = glob($this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR . $langset . '.*'); - $this->load($files); + $appLangDir = $this->app->getAppPath() . 'lang' . DIRECTORY_SEPARATOR; + if (is_dir($appLangDir)) { + $files = []; + + foreach (scandir($appLangDir) as $name) { + $path = $appLangDir . $name; + + if (!str_starts_with($name, $langset) || !is_file($path) || !in_array(pathinfo($name, PATHINFO_EXTENSION), ['php', 'yaml', 'json'])) { + continue; + } + + $files[] = $path; + } + + $this->load($files); + } // 加载扩展(自定义)语言包 $list = $this->app->config->get('lang.extend_list', []); diff --git a/src/think/log/driver/File.php b/src/think/log/driver/File.php index 26c0f99a14..e4dc0b2d11 100644 --- a/src/think/log/driver/File.php +++ b/src/think/log/driver/File.php @@ -135,7 +135,14 @@ protected function getMasterLogFile(): string { if ($this->config['max_files']) { - $files = glob($this->config['path'] . '*.log'); + $files = []; + foreach (scandir($this->config['path']) as $name) { + if (!str_ends_with($name, '.log') || !is_file($this->config['path'] . $name)) { + continue; + } + + $files[] = $this->config['path'] . $name; + } try { if (count($files) > $this->config['max_files']) {