forked from Cavemanon/cavepaintings
Added iterator_map and iterator_map_to_array
Moved the path join/sanitize to pollyfills
This commit is contained in:
@@ -338,37 +338,6 @@ function path_to_tags(string $path): string
|
||||
return implode(" ", $tags);
|
||||
}
|
||||
|
||||
/**
|
||||
* Translates all possible directory separators to the appropriate one for the current system,
|
||||
* and removes any duplicate separators.
|
||||
*/
|
||||
function sanitize_path(string $path): string
|
||||
{
|
||||
return preg_replace('|[\\\\/]+|S',DIRECTORY_SEPARATOR,$path);
|
||||
}
|
||||
|
||||
/**
|
||||
* Combines all path segments specified, ensuring no duplicate separators occur,
|
||||
* as well as converting all possible separators to the one appropriate for the current system.
|
||||
*/
|
||||
function join_path(string ...$paths): string
|
||||
{
|
||||
$output = "";
|
||||
foreach ($paths as $path) {
|
||||
if(empty($path)) {
|
||||
continue;
|
||||
}
|
||||
$path = sanitize_path($path);
|
||||
if(empty($output)) {
|
||||
$output = $path;
|
||||
} else {
|
||||
$output = rtrim($output, DIRECTORY_SEPARATOR);
|
||||
$path = ltrim($path, DIRECTORY_SEPARATOR);
|
||||
$output .= DIRECTORY_SEPARATOR . $path;
|
||||
}
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
function join_url(string $base, string ...$paths)
|
||||
{
|
||||
|
Reference in New Issue
Block a user