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 | * @inheritdoc |
||
77 | */ |
||
78 | 6 | public function __debugInfo() |
|
82 | |||
83 | /** |
||
84 | * Returns an instance without dot segments |
||
85 | * |
||
86 | * This method MUST retain the state of the current instance, and return |
||
87 | * an instance that contains the path component normalized by removing |
||
88 | * the dot segment. |
||
89 | * |
||
90 | * @return static |
||
91 | */ |
||
92 | 165 | public function withoutDotSegments() |
|
107 | |||
108 | /** |
||
109 | * Filter Dot segment according to RFC3986 |
||
110 | * |
||
111 | * @see http://tools.ietf.org/html/rfc3986#section-5.2.4 |
||
112 | * |
||
113 | * @param array $carry Path segments |
||
114 | * @param string $segment a path segment |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | 84 | protected function filterDotSegments(array $carry, $segment) |
|
132 | |||
133 | /** |
||
134 | * Returns an instance without duplicate delimiters |
||
135 | * |
||
136 | * This method MUST retain the state of the current instance, and return |
||
137 | * an instance that contains the path component normalized by removing |
||
138 | * multiple consecutive empty segment |
||
139 | * |
||
140 | * @return static |
||
141 | */ |
||
142 | 15 | public function withoutEmptySegments() |
|
146 | |||
147 | /** |
||
148 | * Returns whether or not the path has a trailing delimiter |
||
149 | * |
||
150 | * @return bool |
||
151 | */ |
||
152 | 60 | public function hasTrailingSlash() |
|
158 | |||
159 | /** |
||
160 | * Returns an instance with a trailing slash |
||
161 | * |
||
162 | * This method MUST retain the state of the current instance, and return |
||
163 | * an instance that contains the path component with a trailing slash |
||
164 | * |
||
165 | * |
||
166 | * @return static |
||
167 | */ |
||
168 | 21 | public function withTrailingSlash() |
|
172 | |||
173 | /** |
||
174 | * Returns an instance without a trailing slash |
||
175 | * |
||
176 | * This method MUST retain the state of the current instance, and return |
||
177 | * an instance that contains the path component without a trailing slash |
||
178 | * |
||
179 | * @return static |
||
180 | */ |
||
181 | 21 | public function withoutTrailingSlash() |
|
185 | |||
186 | /** |
||
187 | * Returns whether or not the path is absolute or relative |
||
188 | * |
||
189 | * @return bool |
||
190 | */ |
||
191 | 153 | public function isAbsolute() |
|
197 | |||
198 | /** |
||
199 | * Returns an instance with a leading slash |
||
200 | * |
||
201 | * This method MUST retain the state of the current instance, and return |
||
202 | * an instance that contains the path component with a leading slash |
||
203 | * |
||
204 | * |
||
205 | * @return static |
||
206 | */ |
||
207 | 24 | public function withLeadingSlash() |
|
211 | |||
212 | /** |
||
213 | * Returns an instance without a leading slash |
||
214 | * |
||
215 | * This method MUST retain the state of the current instance, and return |
||
216 | * an instance that contains the path component without a leading slash |
||
217 | * |
||
218 | * @return static |
||
219 | */ |
||
220 | 21 | public function withoutLeadingSlash() |
|
224 | |||
225 | /** |
||
226 | * Retrieve the optional type associated to the path. |
||
227 | * |
||
228 | * The value returned MUST be one of the interface constant type |
||
229 | * If no type is associated the return constant must be self::FTP_TYPE_EMPTY |
||
230 | * |
||
231 | * @see http://tools.ietf.org/html/rfc1738#section-3.2.2 |
||
232 | * |
||
233 | * @return int a typecode constant. |
||
234 | */ |
||
235 | 18 | public function getTypecode() |
|
243 | |||
244 | /** |
||
245 | * Return an instance with the specified typecode. |
||
246 | * |
||
247 | * This method MUST retain the state of the current instance, and return |
||
248 | * an instance that contains the specified type appended to the path. |
||
249 | * if not |
||
250 | * |
||
251 | * Using self::FTP_TYPE_EMPTY is equivalent to removing the typecode. |
||
252 | * |
||
253 | * @param int $type one typecode constant. |
||
254 | * |
||
255 | * @throws InvalidArgumentException for invalid typecode. |
||
256 | * |
||
257 | * @return static |
||
258 | * |
||
259 | */ |
||
260 | 30 | public function withTypecode($type) |
|
279 | |||
280 | /** |
||
281 | * Encode a path string according to RFC3986 |
||
282 | * |
||
283 | * @param string $subject can be a string or an array |
||
284 | * |
||
285 | * @return string The same type as the input parameter |
||
286 | */ |
||
287 | 1121 | protected static function encodePath($subject) |
|
301 | |||
302 | /** |
||
303 | * Decode a path string according to RFC3986 |
||
304 | * |
||
305 | * @param string $subject can be a string or an array |
||
306 | * |
||
307 | * @return string The same type as the input parameter |
||
308 | */ |
||
309 | protected static function decodePath($subject) |
||
317 | } |
||
318 |