1 | <?php |
||
25 | class HierarchicalPath extends AbstractHierarchicalComponent implements HierarchicalPathInterface |
||
26 | { |
||
27 | use PathTrait; |
||
28 | |||
29 | /** |
||
30 | * @inheritdoc |
||
31 | */ |
||
32 | protected static $separator = '/'; |
||
33 | |||
34 | /** |
||
35 | * DEPRECATION WARNING! This method will be removed in the next major point release |
||
36 | * |
||
37 | * @deprecated deprecated since version 4.2 |
||
38 | * |
||
39 | * return a new instance from an array or a traversable object |
||
40 | * |
||
41 | * @param \Traversable|string[] $data The segments list |
||
42 | * @param int $type one of the constant IS_ABSOLUTE or IS_RELATIVE |
||
43 | * |
||
44 | * @throws InvalidArgumentException If $data is invalid |
||
45 | * @throws InvalidArgumentException If $type is not a recognized constant |
||
46 | * |
||
47 | * @return static |
||
48 | */ |
||
49 | public static function createFromArray($data, $type = self::IS_RELATIVE) |
||
53 | |||
54 | /** |
||
55 | * return a new instance from an array or a traversable object |
||
56 | * |
||
57 | * @param \Traversable|string[] $data The segments list |
||
58 | * @param int $type one of the constant IS_ABSOLUTE or IS_RELATIVE |
||
59 | * |
||
60 | * @throws InvalidArgumentException If $data is invalid |
||
61 | * @throws InvalidArgumentException If $type is not a recognized constant |
||
62 | * |
||
63 | * @return static |
||
64 | */ |
||
65 | 237 | public static function createFromSegments($data, $type = self::IS_RELATIVE) |
|
80 | |||
81 | /** |
||
82 | * New Instance |
||
83 | * |
||
84 | * @param string $path |
||
85 | */ |
||
86 | 1075 | public function __construct($path = '') |
|
106 | |||
107 | /** |
||
108 | * validate the submitted data |
||
109 | * |
||
110 | * @param string $data |
||
111 | * |
||
112 | * @return array |
||
113 | */ |
||
114 | protected function validate($data) |
||
124 | |||
125 | /** |
||
126 | * @inheritdoc |
||
127 | */ |
||
128 | 9 | public static function __set_state(array $properties) |
|
132 | |||
133 | /** |
||
134 | * Return a new instance when needed |
||
135 | * |
||
136 | * @param array $data |
||
137 | * |
||
138 | * @return static |
||
139 | */ |
||
140 | 63 | protected function newCollectionInstance(array $data) |
|
144 | |||
145 | /** |
||
146 | * Returns an array representation of the HierarchicalPath |
||
147 | * |
||
148 | * @return array |
||
149 | */ |
||
150 | 129 | public function getSegments() |
|
154 | |||
155 | /** |
||
156 | * Retrieves a single path segment. |
||
157 | * |
||
158 | * Retrieves a single path segment. If the segment offset has not been set, |
||
159 | * returns the default value provided. |
||
160 | * |
||
161 | * @param string $offset the segment offset |
||
162 | * @param mixed $default Default value to return if the offset does not exist. |
||
163 | * |
||
164 | * @return mixed |
||
165 | */ |
||
166 | 9 | public function getSegment($offset, $default = null) |
|
174 | |||
175 | /** |
||
176 | * @inheritdoc |
||
177 | */ |
||
178 | 1042 | public function getContent() |
|
182 | 812 | ||
183 | 541 | /** |
|
184 | * Return the decoded string representation of the component |
||
185 | 1042 | * |
|
186 | 1042 | * @return string |
|
187 | 694 | */ |
|
188 | public function getDecoded() |
||
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | 30 | public function __toString() |
|
205 | 30 | ||
206 | 30 | /** |
|
207 | * @inheritdoc |
||
208 | */ |
||
209 | public function prepend($component) |
||
216 | |||
217 | /** |
||
218 | * Returns an instance with the specified component appended |
||
219 | 72 | * |
|
220 | * This method MUST retain the state of the current instance, and return |
||
221 | 72 | * an instance that contains the modified component with the appended data |
|
222 | 72 | * |
|
223 | 30 | * @param HierarchicalComponent|string $component the component to append |
|
224 | 20 | * |
|
225 | * @return static |
||
226 | 72 | */ |
|
227 | 48 | public function append($component) |
|
239 | 63 | ||
240 | /** |
||
241 | 63 | * Returns the path basename |
|
242 | * |
||
243 | * @return string |
||
244 | */ |
||
245 | public function getBasename() |
||
251 | 24 | ||
252 | 24 | /** |
|
253 | 24 | * Returns parent directory's path |
|
254 | 24 | * |
|
255 | 16 | * @return string |
|
256 | */ |
||
257 | public function getDirname() |
||
265 | 57 | ||
266 | /** |
||
267 | 57 | * Returns the basename extension |
|
268 | * |
||
269 | * @return string |
||
270 | */ |
||
271 | public function getExtension() |
||
277 | |||
278 | /** |
||
279 | * Returns an instance with the specified basename extension |
||
280 | * |
||
281 | * This method MUST retain the state of the current instance, and return |
||
282 | * an instance that contains the extension basename modified. |
||
283 | 63 | * |
|
284 | * @param string $extension the new extension |
||
285 | 63 | * can preceeded with or without the dot (.) character |
|
286 | 57 | * |
|
287 | 57 | * @throws InvalidArgumentException If the extension is invalid |
|
288 | 57 | * |
|
289 | 57 | * @return static |
|
290 | 57 | */ |
|
291 | 6 | public function withExtension($extension) |
|
310 | |||
311 | /** |
||
312 | 51 | * create a new basename with a new extension |
|
313 | * |
||
314 | 51 | * @param string $basenamePart the basename file part |
|
315 | 51 | * @param string $extension the new extension to add |
|
316 | 45 | * @param string $parameterPart the basename parameter part |
|
317 | 30 | * |
|
318 | * @return string |
||
319 | 51 | */ |
|
320 | 51 | protected function buildBasename($basenamePart, $extension, $parameterPart) |
|
339 | |||
340 | /** |
||
341 | 63 | * validate and format the given extension |
|
342 | * |
||
343 | 63 | * @param string $extension the new extension to use |
|
344 | 3 | * |
|
345 | * @throws InvalidArgumentException If the extension is not valid |
||
346 | * |
||
347 | 60 | * @return string |
|
348 | 3 | */ |
|
349 | protected function formatExtension($extension) |
||
361 | } |
||
362 |