fix: 目录拼错的情况

This commit is contained in:
kuaifan
2024-10-31 23:07:13 +08:00
parent df8fdd56ba
commit cfda858d87
2 changed files with 9 additions and 5 deletions

View File

@@ -2671,10 +2671,14 @@ class Base
*/
public static function joinPath(...$segments)
{
$trimmedSegments = array_map(function ($segment) {
if (count($segments) === 0) {
return "";
}
$array = array_map(function ($segment) {
return trim($segment, DIRECTORY_SEPARATOR);
}, $segments);
return implode(DIRECTORY_SEPARATOR, $trimmedSegments);
$prefix = str_starts_with($segments[0], DIRECTORY_SEPARATOR) ? DIRECTORY_SEPARATOR : "";
return $prefix . implode(DIRECTORY_SEPARATOR, $array);
}
/**