1 | <?php |
||
24 | trait PathTrait |
||
25 | { |
||
26 | /** |
||
27 | * Typecode Regular expression |
||
28 | */ |
||
29 | protected static $typeRegex = ',^(?P<basename>.*);type=(?P<typecode>a|i|d)$,'; |
||
30 | |||
31 | /** |
||
32 | * Paht reserved characters regular expression |
||
33 | */ |
||
34 | protected static $pathReservedCharactersRegex = "/(?:[^\!\$&'\(\)\*\+,;\=\:\/@\?%]+|%(?![A-Fa-f0-9]{2}))/S"; |
||
35 | |||
36 | /** |
||
37 | * Typecode value |
||
38 | * |
||
39 | * @var array |
||
40 | */ |
||
41 | protected static $typecodeList = [ |
||
42 | 'a' => PathInterface::FTP_TYPE_ASCII, |
||
43 | 'i' => PathInterface::FTP_TYPE_BINARY, |
||
44 | 'd' => PathInterface::FTP_TYPE_DIRECTORY, |
||
45 | '' => PathInterface::FTP_TYPE_EMPTY, |
||
46 | ]; |
||
47 | |||
48 | /** |
||
49 | * Dot Segment pattern |
||
50 | * |
||
51 | * @var array |
||
52 | */ |
||
53 | protected static $dotSegments = ['.' => 1, '..' => 1]; |
||
54 | |||
55 | /** |
||
56 | * Returns the instance string representation; If the |
||
57 | * instance is not defined an empty string is returned |
||
58 | * |
||
59 | * @return string |
||
60 | */ |
||
61 | abstract public function __toString(); |
||
62 | |||
63 | /** |
||
64 | * Returns an instance with the specified string |
||
65 | * |
||
66 | * This method MUST retain the state of the current instance, and return |
||
67 | * an instance that contains the modified data |
||
68 | * |
||
69 | * @param string $value |
||
70 | * |
||
71 | * @return static |
||
72 | */ |
||
73 | abstract public function modify($value); |
||
74 | |||
75 | /** |
||
76 | * Returns an instance without dot segments |
||
77 | * |
||
78 | * This method MUST retain the state of the current instance, and return |
||
79 | * an instance that contains the path component normalized by removing |
||
80 | * the dot segment. |
||
81 | * |
||
82 | * @return static |
||
83 | */ |
||
84 | 165 | public function withoutDotSegments() |
|
99 | |||
100 | /** |
||
101 | * Filter Dot segment according to RFC3986 |
||
102 | * |
||
103 | * @see http://tools.ietf.org/html/rfc3986#section-5.2.4 |
||
104 | * |
||
105 | * @param array $carry Path segments |
||
106 | * @param string $segment a path segment |
||
107 | * |
||
108 | * @return array |
||
109 | */ |
||
110 | 84 | protected function filterDotSegments(array $carry, $segment) |
|
124 | |||
125 | /** |
||
126 | * Returns an instance without duplicate delimiters |
||
127 | * |
||
128 | * This method MUST retain the state of the current instance, and return |
||
129 | * an instance that contains the path component normalized by removing |
||
130 | * multiple consecutive empty segment |
||
131 | * |
||
132 | * @return static |
||
133 | */ |
||
134 | 15 | public function withoutEmptySegments() |
|
138 | |||
139 | /** |
||
140 | * Returns whether or not the path has a trailing delimiter |
||
141 | * |
||
142 | * @return bool |
||
143 | */ |
||
144 | 60 | public function hasTrailingSlash() |
|
150 | |||
151 | /** |
||
152 | * Returns an instance with a trailing slash |
||
153 | * |
||
154 | * This method MUST retain the state of the current instance, and return |
||
155 | * an instance that contains the path component with a trailing slash |
||
156 | * |
||
157 | * |
||
158 | * @return static |
||
159 | */ |
||
160 | 21 | public function withTrailingSlash() |
|
164 | |||
165 | /** |
||
166 | * Returns an instance without a trailing slash |
||
167 | * |
||
168 | * This method MUST retain the state of the current instance, and return |
||
169 | * an instance that contains the path component without a trailing slash |
||
170 | * |
||
171 | * @return static |
||
172 | */ |
||
173 | 21 | public function withoutTrailingSlash() |
|
177 | |||
178 | /** |
||
179 | * Returns whether or not the path is absolute or relative |
||
180 | * |
||
181 | * @return bool |
||
182 | */ |
||
183 | 153 | public function isAbsolute() |
|
189 | |||
190 | /** |
||
191 | * Returns an instance with a leading slash |
||
192 | * |
||
193 | * This method MUST retain the state of the current instance, and return |
||
194 | * an instance that contains the path component with a leading slash |
||
195 | * |
||
196 | * |
||
197 | * @return static |
||
198 | */ |
||
199 | 24 | public function withLeadingSlash() |
|
203 | |||
204 | /** |
||
205 | * Returns an instance without a leading slash |
||
206 | * |
||
207 | * This method MUST retain the state of the current instance, and return |
||
208 | * an instance that contains the path component without a leading slash |
||
209 | * |
||
210 | * @return static |
||
211 | */ |
||
212 | 21 | public function withoutLeadingSlash() |
|
216 | |||
217 | /** |
||
218 | * Retrieve the optional type associated to the path. |
||
219 | * |
||
220 | * The value returned MUST be one of the interface constant type |
||
221 | * If no type is associated the return constant must be self::FTP_TYPE_EMPTY |
||
222 | * |
||
223 | * @see http://tools.ietf.org/html/rfc1738#section-3.2.2 |
||
224 | * |
||
225 | * @return int a typecode constant. |
||
226 | */ |
||
227 | 18 | public function getTypecode() |
|
235 | |||
236 | /** |
||
237 | * Return an instance with the specified typecode. |
||
238 | * |
||
239 | * This method MUST retain the state of the current instance, and return |
||
240 | * an instance that contains the specified type appended to the path. |
||
241 | * if not |
||
242 | * |
||
243 | * Using self::FTP_TYPE_EMPTY is equivalent to removing the typecode. |
||
244 | * |
||
245 | * @param int $type one typecode constant. |
||
246 | * |
||
247 | * @throws InvalidArgumentException for invalid typecode. |
||
248 | * |
||
249 | * @return static |
||
250 | * |
||
251 | */ |
||
252 | 30 | public function withTypecode($type) |
|
271 | |||
272 | /** |
||
273 | * Encode a path string according to RFC3986 |
||
274 | * |
||
275 | * @param string $subject can be a string or an array |
||
276 | * |
||
277 | * @return string The same type as the input parameter |
||
278 | */ |
||
279 | 1101 | protected static function encodePath($subject) |
|
293 | |||
294 | /** |
||
295 | * Decode a path string according to RFC3986 |
||
296 | * |
||
297 | * @param string $subject can be a string or an array |
||
298 | * |
||
299 | * @return string The same type as the input parameter |
||
300 | */ |
||
301 | protected static function decodePath($subject) |
||
309 | } |
||
310 |