diff --git a/plugin/think-library/src/Library.php b/plugin/think-library/src/Library.php index 2880381cc..b11eb0b9e 100644 --- a/plugin/think-library/src/Library.php +++ b/plugin/think-library/src/Library.php @@ -18,6 +18,8 @@ declare (strict_types=1); namespace think\admin; +use SplFileInfo; +use think\admin\extend\ToolsExtend; use think\admin\service\RuntimeService; use think\admin\support\command\Database; use think\admin\support\command\Package; @@ -106,7 +108,9 @@ class Library extends Service { // 动态加载全局配置 [$dir, $ext] = [$this->app->getBasePath(), $this->app->getConfigExt()]; - foreach (glob("{$dir}*/sys{$ext}") as $file) include_once $file; + ToolsExtend::findFilesYield($dir, static function (SplFileInfo $info) use ($ext) { + $info->getBasename() === "sys{$ext}" && include_once $info->getPathname(); + }); if (is_file($file = "{$dir}common{$ext}")) include_once $file; if (is_file($file = "{$dir}provider{$ext}")) $this->app->bind(include $file); if (is_file($file = "{$dir}event{$ext}")) $this->app->loadEvent(include $file); diff --git a/plugin/think-library/src/extend/PhinxExtend.php b/plugin/think-library/src/extend/PhinxExtend.php index c707314d7..2e15c014e 100644 --- a/plugin/think-library/src/extend/PhinxExtend.php +++ b/plugin/think-library/src/extend/PhinxExtend.php @@ -20,6 +20,7 @@ namespace think\admin\extend; use Exception; use Phinx\Db\Adapter\AdapterInterface; +use SplFileInfo; use think\admin\Library; use think\admin\model\SystemMenu; use think\admin\service\ProcessService; @@ -290,20 +291,22 @@ CODE; */ private static function nextFile(string $class): string { - [$filename, $versions, $start] = [Str::snake($class), [], 20009999999999]; - if (count($files = glob(syspath('database/migrations/*.php'))) > 0) { - foreach ($files as $file) { - $versions[] = $version = intval(substr($bname = pathinfo($file, 8), 0, 14)); - if ($filename === substr($bname, 15) && unlink($file)) { - echo " ** Notify: Class {$class} already exists and has been replaced." . PHP_EOL; - if (is_dir($dataPath = dirname($file) . DIRECTORY_SEPARATOR . $version)) { - ToolsExtend::removeEmptyDirectory($dataPath); - } + [$filename, $versions, $startVersion] = [Str::snake($class), [], 20009999999999]; + ToolsExtend::findFilesYield(syspath('database/migrations'), static function (SplFileInfo $info) use ($class, $filename, &$versions) { + $bname = pathinfo($info->getBasename(), PATHINFO_FILENAME); + $versions[] = $version = intval(substr($bname, 0, 14)); + if ($filename === substr($bname, 15) && unlink($info->getRealPath())) { + echo " ** Notify: Class {$class} already exists and has been replaced." . PHP_EOL; + if (is_dir($dataPath = dirname($info->getRealPath()) . DIRECTORY_SEPARATOR . $version)) { + ToolsExtend::removeEmptyDirectory($dataPath); } } - $version = min($versions) - 1; - } - if (!isset($version) || $version > $start) $version = $start; + }); + + // 计算下一个版本号 + $version = !empty($versions) ? min($versions) - 1 : $startVersion; + $version = min($version, $startVersion); + return "{$version}_{$filename}.php"; } } \ No newline at end of file diff --git a/plugin/think-library/src/support/middleware/MultAccess.php b/plugin/think-library/src/support/middleware/MultAccess.php index 807e3efcb..b82db5972 100644 --- a/plugin/think-library/src/support/middleware/MultAccess.php +++ b/plugin/think-library/src/support/middleware/MultAccess.php @@ -19,6 +19,8 @@ declare (strict_types=1); namespace think\admin\support\middleware; use Closure; +use SplFileInfo; +use think\admin\extend\ToolsExtend; use think\admin\Plugin; use think\admin\service\NodeService; use think\admin\service\SystemService; @@ -165,9 +167,11 @@ class MultAccess { [$ext, $fmaps] = [$this->app->getConfigExt(), []]; if (is_file($file = "{$appPath}common{$ext}")) include_once $file; - foreach (glob($appPath . 'config' . DIRECTORY_SEPARATOR . '*' . $ext) as $file) { - $this->app->config->load($file, $fmaps[] = pathinfo($file, PATHINFO_FILENAME)); - } + ToolsExtend::findFilesYield($appPath . 'config', static function (SplFileInfo $info) use ($ext) { + if (strtolower(".{$info->getExtension()}") === "{$ext}") { + $this->app->config->load($info->getPathname(), $info->getBasename($ext)); + } + }); if (in_array('route', $fmaps) && method_exists($this->app->route, 'reload')) { $this->app->route->reload(); }