From 7ba7fd9627f98953fd845dfea5a9fd616bc45b61 Mon Sep 17 00:00:00 2001 From: Inhere Date: Sun, 16 Apr 2023 13:33:39 +0800 Subject: [PATCH] up: update some find logic and update some util method --- src/Extra/FileFinder.php | 4 +++- src/FileSystem.php | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/Extra/FileFinder.php b/src/Extra/FileFinder.php index 391f555..d85bcbb 100644 --- a/src/Extra/FileFinder.php +++ b/src/Extra/FileFinder.php @@ -726,6 +726,7 @@ public function hasChildren(bool $allowLinks = false): bool if (!$this->recursive) { return false; } + return parent::hasChildren($allowLinks); } @@ -743,7 +744,8 @@ public function getChildren(): RecursiveDirectoryIterator return $children; } catch (UnexpectedValueException $e) { if ($this->skipUnreadableDirs) { - return new RecursiveArrayIterator([]); + return $this; + // return null; // return new RecursiveDirectoryIterator([]); } diff --git a/src/FileSystem.php b/src/FileSystem.php index 975f023..698e495 100644 --- a/src/FileSystem.php +++ b/src/FileSystem.php @@ -201,6 +201,9 @@ public static function joinPath(string $basePath, string ...$subPaths): string if (!$subPaths) { return $basePath; } + if (!$basePath) { + return implode(DIRECTORY_SEPARATOR, $subPaths); + } return $basePath . DIRECTORY_SEPARATOR . implode(DIRECTORY_SEPARATOR, $subPaths); } @@ -253,15 +256,26 @@ public static function assertIsDir(string $dirPath): void } } + /** + * @param string $file + * @param string $type + * + * @return bool + */ + public static function exists(string $file, string $type = ''): bool + { + return self::isExists($file, $type); + } + /** * 检查文件/夹/链接是否存在 * * @param string $file 要检查的目标 - * @param string $type + * @param string $type file, dir, link * * @return bool */ - public static function exists(string $file, string $type = ''): bool + public static function isExists(string $file, string $type = ''): bool { if (!$type) { return file_exists($file);