Added iterator_map and iterator_map_to_array

Moved the path join/sanitize to pollyfills
This commit is contained in:
matthew
2019-07-05 11:07:27 -05:00
committed by Shish
parent 490f1f97ed
commit c906df6956
5 changed files with 126 additions and 114 deletions

View File

@@ -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)
{