From 752680a7cca1b4be1ccd21f611d56f2d9897df1b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=82=B9=E6=99=AF=E7=AB=8B?= Date: Tue, 10 Sep 2024 09:47:48 +0800 Subject: [PATCH] Update ToolsExtend.php --- plugin/think-library/src/extend/ToolsExtend.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/plugin/think-library/src/extend/ToolsExtend.php b/plugin/think-library/src/extend/ToolsExtend.php index 4f7f548d1..2394934dc 100644 --- a/plugin/think-library/src/extend/ToolsExtend.php +++ b/plugin/think-library/src/extend/ToolsExtend.php @@ -107,14 +107,14 @@ class ToolsExtend */ public static function findFilesArray(string $path, ?Closure $filterFile = null, ?Closure $filterPath = null, bool $short = true, ?int $depth = null): array { - $files = []; - if (is_file($path)) { - if (($file = new SplFileInfo($path)) && ($filterFile === null || $filterFile($file))) { - $files[] = $short ? $file->getBasename() : $file->getPathname(); + [$info, $files] = [new SplFileInfo($path), []]; + if ($info->isFile()) { + if ($filterFile === null || $filterFile($info)) { + $files[] = $short ? $info->getBasename() : $info->getPathname(); } - } elseif (is_dir($path)) { - foreach (static::findFilesYield($path, $filterFile, $filterPath, $depth) as $file) { - $files[] = $short ? substr($file->getRealPath(), strlen($path) + 1) : $file->getRealPath(); + } elseif ($info->isDir()) { + foreach (static::findFilesYield($info->getPathname(), $filterFile, $filterPath, $depth) as $file) { + $files[] = $short ? substr($file->getRealPath(), strlen($info->getPathname()) + 1) : $file->getRealPath(); } } return $files;