diff --git a/packages/framework/src/Foundation/Kernel/Filesystem.php b/packages/framework/src/Foundation/Kernel/Filesystem.php index 97fa11bec30..9b3cc6cc24c 100644 --- a/packages/framework/src/Foundation/Kernel/Filesystem.php +++ b/packages/framework/src/Foundation/Kernel/Filesystem.php @@ -9,12 +9,12 @@ use Hyde\Foundation\PharSupport; use Illuminate\Support\Collection; +use function collect; use function Hyde\normalize_slashes; use function Hyde\path_join; use function file_exists; use function str_replace; use function array_map; -use function is_string; use function is_array; use function str_starts_with; use function unslash; @@ -70,6 +70,7 @@ public function path(string $path = ''): string * Input types are matched, meaning that if the input is a string so will the output be. * * @param string|array $path + * @return ($path is string ? string : array) */ public function pathToAbsolute(string|array $path): string|array { @@ -99,9 +100,7 @@ public function mediaPath(string $path = ''): string return $this->path(Hyde::getMediaDirectory()); } - $path = unslash($path); - - return $this->path(Hyde::getMediaDirectory()."/$path"); + return $this->path(path_join(Hyde::getMediaDirectory(), unslash($path))); } /** @@ -113,9 +112,7 @@ public function sitePath(string $path = ''): string return $this->path(Hyde::getOutputDirectory()); } - $path = unslash($path); - - return $this->path(Hyde::getOutputDirectory()."/$path"); + return $this->path(path_join(Hyde::getOutputDirectory(), unslash($path))); } /** @@ -153,15 +150,9 @@ public function vendorPath(string $path = '', string $package = 'framework'): st */ public function touch(string|array $path): bool { - if (is_string($path)) { + return collect($path)->map(function (string $path): bool { return touch($this->path($path)); - } - - foreach ($path as $p) { - touch($this->path($p)); - } - - return true; + })->contains(false) === false; } /** @@ -171,15 +162,9 @@ public function touch(string|array $path): bool */ public function unlink(string|array $path): bool { - if (is_string($path)) { + return collect($path)->map(function (string $path): bool { return unlink($this->path($path)); - } - - foreach ($path as $p) { - unlink($this->path($p)); - } - - return true; + })->contains(false) === false; } /** @@ -187,11 +172,7 @@ public function unlink(string|array $path): bool */ public function unlinkIfExists(string $path): bool { - if (file_exists($this->path($path))) { - return unlink($this->path($path)); - } - - return false; + return file_exists($this->path($path)) && unlink($this->path($path)); } /** @return \Illuminate\Support\Collection */