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 | * Typecode value |
||
33 | * |
||
34 | * @var array |
||
35 | */ |
||
36 | protected static $typecodeList = [ |
||
37 | 'a' => PathInterface::FTP_TYPE_ASCII, |
||
38 | 'i' => PathInterface::FTP_TYPE_BINARY, |
||
39 | 'd' => PathInterface::FTP_TYPE_DIRECTORY, |
||
40 | '' => PathInterface::FTP_TYPE_EMPTY, |
||
41 | ]; |
||
42 | |||
43 | /** |
||
44 | * Dot Segment pattern |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | protected static $dotSegments = ['.' => 1, '..' => 1]; |
||
49 | |||
50 | /** |
||
51 | * Filter the encoded path string |
||
52 | * |
||
53 | * @param string $str the encoded path |
||
54 | * |
||
55 | * @throws InvalidArgumentException If the encoded path is invalid |
||
56 | * |
||
57 | * @return string |
||
58 | */ |
||
59 | protected function filterEncodedPath($str) |
||
70 | |||
71 | /** |
||
72 | * Returns the instance string representation; If the |
||
73 | * instance is not defined an empty string is returned |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | abstract public function __toString(); |
||
78 | |||
79 | /** |
||
80 | * Returns an instance with the specified string |
||
81 | * |
||
82 | * This method MUST retain the state of the current instance, and return |
||
83 | * an instance that contains the modified data |
||
84 | * |
||
85 | * @param string $value |
||
86 | * |
||
87 | * @return static |
||
88 | */ |
||
89 | abstract public function withContent($value = null); |
||
90 | |||
91 | 6 | /** |
|
92 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
93 | 6 | * |
|
94 | * @deprecated deprecated since version 4.2 |
||
95 | * |
||
96 | * @see withContent |
||
97 | * |
||
98 | * Returns an instance with the specified string |
||
99 | * |
||
100 | * This method MUST retain the state of the current instance, and return |
||
101 | * an instance that contains the modified data |
||
102 | * |
||
103 | * @param string $value |
||
104 | * |
||
105 | * @return static |
||
106 | */ |
||
107 | abstract public function modify($value); |
||
108 | |||
109 | /** |
||
110 | * @inheritdoc |
||
111 | */ |
||
112 | 228 | public function __debugInfo() |
|
116 | 93 | ||
117 | /** |
||
118 | * The component raw data |
||
119 | 138 | * |
|
120 | 138 | * @return mixed |
|
121 | 138 | */ |
|
122 | 45 | abstract public function getContent(); |
|
123 | 30 | ||
124 | /** |
||
125 | 138 | * Returns an instance without dot segments |
|
126 | * |
||
127 | * This method MUST retain the state of the current instance, and return |
||
128 | * an instance that contains the path component normalized by removing |
||
129 | * the dot segment. |
||
130 | * |
||
131 | * @return static |
||
132 | */ |
||
133 | public function withoutDotSegments() |
||
148 | 92 | ||
149 | /** |
||
150 | 138 | * Filter Dot segment according to RFC3986 |
|
151 | * |
||
152 | * @see http://tools.ietf.org/html/rfc3986#section-5.2.4 |
||
153 | * |
||
154 | * @param array $carry Path segments |
||
155 | * @param string $segment a path segment |
||
156 | * |
||
157 | * @return array |
||
158 | */ |
||
159 | protected function filterDotSegments(array $carry, $segment) |
||
173 | |||
174 | 60 | /** |
|
175 | * Returns an instance without duplicate delimiters |
||
176 | 60 | * |
|
177 | * This method MUST retain the state of the current instance, and return |
||
178 | * an instance that contains the path component normalized by removing |
||
179 | * multiple consecutive empty segment |
||
180 | * |
||
181 | * @return static |
||
182 | */ |
||
183 | public function withoutEmptySegments() |
||
187 | |||
188 | 21 | /** |
|
189 | * Returns whether or not the path has a trailing delimiter |
||
190 | 21 | * |
|
191 | * @return bool |
||
192 | */ |
||
193 | public function hasTrailingSlash() |
||
199 | |||
200 | /** |
||
201 | 21 | * Returns an instance with a trailing slash |
|
202 | * |
||
203 | 21 | * This method MUST retain the state of the current instance, and return |
|
204 | * an instance that contains the path component with a trailing slash |
||
205 | * |
||
206 | * |
||
207 | * @return static |
||
208 | */ |
||
209 | public function withTrailingSlash() |
||
213 | 180 | ||
214 | /** |
||
215 | 180 | * Returns an instance without a trailing slash |
|
216 | * |
||
217 | * This method MUST retain the state of the current instance, and return |
||
218 | * an instance that contains the path component without a trailing slash |
||
219 | * |
||
220 | * @return static |
||
221 | */ |
||
222 | public function withoutTrailingSlash() |
||
226 | |||
227 | 150 | /** |
|
228 | * Returns whether or not the path is absolute or relative |
||
229 | 150 | * |
|
230 | * @return bool |
||
231 | */ |
||
232 | public function isAbsolute() |
||
238 | |||
239 | /** |
||
240 | 18 | * Returns an instance with a leading slash |
|
241 | * |
||
242 | 18 | * This method MUST retain the state of the current instance, and return |
|
243 | * an instance that contains the path component with a leading slash |
||
244 | * |
||
245 | * |
||
246 | * @return static |
||
247 | */ |
||
248 | public function withLeadingSlash() |
||
252 | |||
253 | /** |
||
254 | * Returns an instance without a leading slash |
||
255 | * |
||
256 | * This method MUST retain the state of the current instance, and return |
||
257 | * an instance that contains the path component without a leading slash |
||
258 | * |
||
259 | * @return static |
||
260 | */ |
||
261 | public function withoutLeadingSlash() |
||
265 | |||
266 | /** |
||
267 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
268 | * |
||
269 | * @deprecated deprecated since version 4.2 |
||
270 | * |
||
271 | * Retrieve the optional type associated to the path. |
||
272 | * |
||
273 | * The value returned MUST be one of the interface constant type |
||
274 | * If no type is associated the return constant must be self::FTP_TYPE_EMPTY |
||
275 | * |
||
276 | * @see http://tools.ietf.org/html/rfc1738#section-3.2.2 |
||
277 | * |
||
278 | * @return int a typecode constant. |
||
279 | */ |
||
280 | public function getTypecode() |
||
288 | |||
289 | /** |
||
290 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
291 | * |
||
292 | * @deprecated deprecated since version 4.2 |
||
293 | * |
||
294 | * Return an instance with the specified typecode. |
||
295 | * |
||
296 | * This method MUST retain the state of the current instance, and return |
||
297 | * an instance that contains the specified type appended to the path. |
||
298 | * if not |
||
299 | * |
||
300 | * Using self::FTP_TYPE_EMPTY is equivalent to removing the typecode. |
||
301 | * |
||
302 | * @param int $type one typecode constant. |
||
303 | * |
||
304 | * @throws InvalidArgumentException for invalid typecode. |
||
305 | * |
||
306 | * @return static |
||
307 | * |
||
308 | */ |
||
309 | public function withTypecode($type) |
||
328 | } |
||
329 |