Actions
Feature #15208
closedBest Practice: a) Funktion Path::join() besprechen, b) cache
Status:
Closed
Priority:
Normal
Assignee:
Enis Nuredini
Target version:
-
Start date:
17.12.2022
Due date:
% Done:
0%
Estimated time:
Discuss:
Prio Planung:
No
Vote:
Description
public static function join(...$pathPartsToAppend): string { $parts = $pathPartsToAppend; // concatenate all parts (arrays are flattened) $path = ''; array_walk_recursive($parts, function ($part) use (&$path) { // filter out empty string and null arguments if (is_null($part) || $part === '') { return; } // first part added without '/' if ($path === '') { $path .= $part; } else { $part = (string)$part; $path .= ((($part[0] ?? '') === '/')?'':'/') . $part; } }); // remove multiple occurrences of '/' (but keep http://) if (preg_match('/^\w*:\/\//', $path, $match)) { $protocol = $match[0]; $path = substr($path, strlen($protocol)); } else { $protocol = ''; } $path = preg_replace('/\/{2,}/', '/', $path); return $protocol . $path; }
Files
Related issues
Actions