1 | <?php |
||
7 | final class Path |
||
8 | { |
||
9 | private $scheme = ''; |
||
10 | private $path = ''; |
||
11 | |||
12 | /** |
||
13 | * Combine any amount of strings into a path. |
||
14 | * |
||
15 | * @param string|array ...$paths One or as many parameters as you need. Both strings and arrays of strings can be mixed. |
||
16 | * |
||
17 | * @return string The combined paths. Note that the directory separators will be changed to reflect the local system. |
||
18 | */ |
||
19 | public static function combine(...$paths) |
||
38 | |||
39 | /** |
||
40 | * Localize directory separators for any file path according to current environment. |
||
41 | * |
||
42 | * @param string $path |
||
43 | * @param string $directorySeparator |
||
44 | * |
||
45 | * @return string |
||
46 | */ |
||
47 | public static function localize($path, $directorySeparator = DIRECTORY_SEPARATOR) |
||
55 | |||
56 | /** |
||
57 | * Contains returns true if a base path contains a needle. |
||
58 | * |
||
59 | * Note that `realpath` is used on both base and needle: they need to exist or false is returned. |
||
60 | * |
||
61 | * Use this for avoiding directory traversal outside of a base path. |
||
62 | * |
||
63 | * @param string $base Path to base directory. |
||
64 | * @param string $needle Needle that must exist within the base directory. |
||
65 | * |
||
66 | * @return bool True if both exist and needle does not escape the base folder. |
||
67 | */ |
||
68 | public static function contains($base, $needle) |
||
77 | |||
78 | /** |
||
79 | * isAbsolute checks for an absolute UNIX or Windows path. |
||
80 | * |
||
81 | * @param string $path |
||
82 | * |
||
83 | * @return bool True if the path is absolute. |
||
84 | */ |
||
85 | public static function isAbsolute($path) |
||
89 | |||
90 | public function __toString() |
||
94 | |||
95 | /** |
||
96 | * @param string $fullPath |
||
97 | * |
||
98 | * @return \nochso\Omni\Path |
||
99 | */ |
||
100 | private static function create($fullPath) |
||
113 | } |
||
114 |