From 735323b97376cf7d80e4fcd593522f38646ddc65 Mon Sep 17 00:00:00 2001 From: jwj <86849180@qq.com> Date: Fri, 6 Sep 2024 17:00:59 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=AF=B9=20Phar=20?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=20https://github.com/top-think/fram?= =?UTF-8?q?ework/issues/3049?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/App.php | 12 +++++------- src/think/Http.php | 7 ++++--- src/think/Lang.php | 18 ++++++++++++++++-- src/think/log/driver/File.php | 7 ++++++- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/think/App.php b/src/think/App.php index f4dcc2f99b..4597b369b1 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,12 @@ 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..ef8ff8b4b5 100644 --- a/src/think/Http.php +++ b/src/think/Http.php @@ -229,9 +229,10 @@ protected function loadRoutes(): void $routePath = $this->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..81cd345205 100644 --- a/src/think/log/driver/File.php +++ b/src/think/log/driver/File.php @@ -135,7 +135,12 @@ 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']) { From a7edf85fd178ab8a7940a8011a99c58f6664b6b3 Mon Sep 17 00:00:00 2001 From: jwj <86849180@qq.com> Date: Fri, 6 Sep 2024 17:18:07 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F(PER-CS2.0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/think/App.php | 4 +++- src/think/Http.php | 5 ++++- src/think/log/driver/File.php | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/think/App.php b/src/think/App.php index 4597b369b1..123db4984f 100644 --- a/src/think/App.php +++ b/src/think/App.php @@ -540,7 +540,9 @@ protected function load(): void if (is_dir($configPath)) { foreach (scandir($configPath) as $name) { - if (!str_ends_with($name, $this->configExt) || !is_file($configPath . $name)) continue; + if (!str_ends_with($name, $this->configExt) || !is_file($configPath . $name)) { + continue; + } $this->config->load($configPath . $name, pathinfo($name, PATHINFO_FILENAME)); } diff --git a/src/think/Http.php b/src/think/Http.php index ef8ff8b4b5..ded021177a 100644 --- a/src/think/Http.php +++ b/src/think/Http.php @@ -1,4 +1,5 @@ config['max_files']) { $files = []; foreach (scandir($this->config['path']) as $name) { - if (!str_ends_with($name, '.log') || !is_file($this->config['path'] . $name)) continue; + if (!str_ends_with($name, '.log') || !is_file($this->config['path'] . $name)) { + continue; + } $files[] = $this->config['path'] . $name; }