1 | <?php |
||
15 | class Path |
||
16 | { |
||
17 | /** |
||
18 | * Date placeholder replacement. |
||
19 | * Replaces %{somevalue} with date({somevalue}). |
||
20 | * |
||
21 | * @param string $string |
||
22 | * @param mixed <integer|null> $time |
||
23 | * @return string |
||
24 | */ |
||
25 | 74 | public static function replaceDatePlaceholders($string, $time = null) |
|
36 | |||
37 | /** |
||
38 | * Does a given string contain a date placeholder. |
||
39 | * |
||
40 | * @param string $string |
||
41 | * @return bool |
||
42 | */ |
||
43 | 47 | public static function isContainingPlaceholder($string) |
|
47 | |||
48 | /** |
||
49 | * Replaces %TARGET_DIR% and %TARGET_FILE% in given string. |
||
50 | * |
||
51 | * @param string $string |
||
52 | * @param string $target |
||
53 | * @return string |
||
54 | */ |
||
55 | 4 | public static function replaceTargetPlaceholders($string, $target) |
|
62 | |||
63 | /** |
||
64 | * Create a regex that matches the raw path considering possible date placeholders. |
||
65 | * |
||
66 | * @param string $stringWithDatePlaceholders |
||
67 | * @return string |
||
68 | */ |
||
69 | 14 | public static function datePlaceholdersToRegex($stringWithDatePlaceholders) |
|
74 | |||
75 | /** |
||
76 | * Determine if the path has a trailing slash. |
||
77 | * |
||
78 | * @param string $string |
||
79 | * @return bool |
||
80 | */ |
||
81 | 28 | public static function hasTrailingSlash(string $string) : bool |
|
85 | |||
86 | /** |
||
87 | * Adds trailing slash to a string/path if not already there. |
||
88 | * |
||
89 | * @param string $string |
||
90 | * @return string |
||
91 | */ |
||
92 | 21 | public static function withTrailingSlash($string) |
|
96 | |||
97 | /** |
||
98 | * Removes the trailing slash from a string/path. |
||
99 | * |
||
100 | * @param string $string |
||
101 | * @return string |
||
102 | */ |
||
103 | 6 | public static function withoutTrailingSlash($string) |
|
107 | |||
108 | /** |
||
109 | * Determine if the path has a leading slash. |
||
110 | * |
||
111 | * @param string $string |
||
112 | * @return bool |
||
113 | */ |
||
114 | 25 | public static function hasLeadingSlash(string $string) : bool |
|
118 | |||
119 | /** |
||
120 | * Adds leading slash to a string/path if not already there. |
||
121 | * |
||
122 | * @param string $string |
||
123 | * @return string |
||
124 | */ |
||
125 | 6 | public static function withLeadingSlash($string) |
|
129 | |||
130 | /** |
||
131 | * Removes the leading slash from a string/path. |
||
132 | * |
||
133 | * @param string $string |
||
134 | * @return string |
||
135 | */ |
||
136 | 2 | public static function withoutLeadingSlash($string) |
|
140 | |||
141 | /** |
||
142 | * Is given path absolute. |
||
143 | * |
||
144 | * @param string $path |
||
145 | * @return bool |
||
146 | */ |
||
147 | 49 | public static function isAbsolutePath($path) : bool |
|
173 | |||
174 | /** |
||
175 | * Is given path an absolute windows path. |
||
176 | * |
||
177 | * @param string $path |
||
178 | * @return bool |
||
179 | */ |
||
180 | 3 | public static function isAbsoluteWindowsPath($path) : bool |
|
184 | |||
185 | /** |
||
186 | * Converts a path to an absolute one if necessary relative to a given base path. |
||
187 | * |
||
188 | * @param string $path |
||
189 | * @param string $base |
||
190 | * @param boolean $useIncludePath |
||
191 | * @return string |
||
192 | */ |
||
193 | 46 | public static function toAbsolutePath(string $path, string $base, bool $useIncludePath = false) : string |
|
209 | |||
210 | /** |
||
211 | * Return list of directories in a given path without absolute root element |
||
212 | * |
||
213 | * @param string $path |
||
214 | * @return array |
||
215 | */ |
||
216 | 16 | public static function getDirectoryListFromPath($path): array |
|
222 | |||
223 | /** |
||
224 | * Return list of directories in a given path with absolute root element. |
||
225 | * |
||
226 | * @param string $path |
||
227 | * @return array |
||
228 | */ |
||
229 | 16 | public static function getDirectoryListFromAbsolutePath(string $path) : array |
|
237 | |||
238 | /** |
||
239 | * Returns directory depth of a given path. |
||
240 | * |
||
241 | * @param string $path |
||
242 | * @return int |
||
243 | */ |
||
244 | 10 | public static function getPathDepth(string $path) : int |
|
248 | } |
||
249 |