1 | <?php |
||
7 | final class Path { |
||
8 | /** |
||
9 | * Combine any amount of strings into a path. |
||
10 | * |
||
11 | * @param string|array ...$paths One or as many parameters as you need. Both strings and arrays of strings can be mixed. |
||
12 | * |
||
13 | * @return string The combined paths. Note that the directory separators will be changed to reflect the local system. |
||
14 | */ |
||
15 | public static function combine(...$paths) { |
||
30 | |||
31 | /** |
||
32 | * Localize directory separators for any file path according to current environment. |
||
33 | * |
||
34 | * @param string $path |
||
35 | * @param string $directorySeparator |
||
36 | * |
||
37 | * @return string |
||
38 | */ |
||
39 | public static function localize($path, $directorySeparator = DIRECTORY_SEPARATOR) { |
||
49 | |||
50 | /** |
||
51 | * Contains returns true if a base path contains a needle. |
||
52 | * |
||
53 | * Note that `realpath` is used on both base and needle: they need to exist or false is returned. |
||
54 | * |
||
55 | * Use this for avoiding directory traversal outside of a base path. |
||
56 | * |
||
57 | * @param string $base Path to base directory. |
||
58 | * @param string $needle Needle that must exist within the base directory. |
||
59 | * |
||
60 | * @return bool True if both exist and needle does not escape the base folder. |
||
61 | */ |
||
62 | public static function contains($base, $needle) { |
||
70 | |||
71 | /** |
||
72 | * isAbsolute checks for an absolute UNIX, Windows or scheme:// path. |
||
73 | * |
||
74 | * Note that paths containing parent dots (`..`) can still be considered absolute. |
||
75 | * |
||
76 | * @param string $path |
||
77 | * |
||
78 | * @return bool True if the path is absolute i.e. it should be safe to append a relative path to it. |
||
79 | */ |
||
80 | public static function isAbsolute($path) { |
||
89 | |||
90 | private static function extractScheme(&$parts) { |
||
104 | } |
||
105 |