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) |
||
126 | |||
127 | /** |
||
128 | 9 | * @inheritdoc |
|
129 | */ |
||
130 | 9 | public static function __set_state(array $properties) |
|
134 | |||
135 | /** |
||
136 | * Return a new instance when needed |
||
137 | * |
||
138 | * @param array $data |
||
139 | * |
||
140 | 63 | * @return static |
|
141 | */ |
||
142 | 63 | protected function newCollectionInstance(array $data) |
|
146 | |||
147 | /** |
||
148 | * Returns an array representation of the HierarchicalPath |
||
149 | * |
||
150 | 129 | * @return array |
|
151 | */ |
||
152 | 129 | public function getSegments() |
|
156 | |||
157 | /** |
||
158 | * Retrieves a single path segment. |
||
159 | * |
||
160 | * Retrieves a single path segment. If the segment offset has not been set, |
||
161 | * returns the default value provided. |
||
162 | * |
||
163 | * @param string $offset the segment offset |
||
164 | * @param mixed $default Default value to return if the offset does not exist. |
||
165 | * |
||
166 | 9 | * @return mixed |
|
167 | */ |
||
168 | 9 | public function getSegment($offset, $default = null) |
|
176 | |||
177 | /** |
||
178 | 1042 | * @inheritdoc |
|
179 | */ |
||
180 | 1042 | public function getContent() |
|
189 | |||
190 | /** |
||
191 | * @inheritdoc |
||
192 | */ |
||
193 | 1042 | public function __toString() |
|
197 | |||
198 | /** |
||
199 | * @inheritdoc |
||
200 | */ |
||
201 | 30 | public function prepend($component) |
|
208 | |||
209 | /** |
||
210 | * Returns an instance with the specified component appended |
||
211 | * |
||
212 | * This method MUST retain the state of the current instance, and return |
||
213 | * an instance that contains the modified component with the appended data |
||
214 | * |
||
215 | * @param HierarchicalComponent|string $component the component to append |
||
216 | * |
||
217 | * @return static |
||
218 | */ |
||
219 | 72 | public function append($component) |
|
231 | |||
232 | /** |
||
233 | * Returns the path basename |
||
234 | * |
||
235 | * @return string |
||
236 | */ |
||
237 | 63 | public function getBasename() |
|
243 | |||
244 | /** |
||
245 | * Returns parent directory's path |
||
246 | * |
||
247 | * @return string |
||
248 | */ |
||
249 | 24 | public function getDirname() |
|
257 | |||
258 | /** |
||
259 | * Returns the basename extension |
||
260 | * |
||
261 | * @return string |
||
262 | */ |
||
263 | 57 | public function getExtension() |
|
269 | |||
270 | /** |
||
271 | * Returns an instance with the specified basename extension |
||
272 | * |
||
273 | * This method MUST retain the state of the current instance, and return |
||
274 | * an instance that contains the extension basename modified. |
||
275 | * |
||
276 | * @param string $extension the new extension |
||
277 | * can preceeded with or without the dot (.) character |
||
278 | * |
||
279 | * @throws InvalidArgumentException If the extension is invalid |
||
280 | * |
||
281 | * @return static |
||
282 | */ |
||
283 | 63 | public function withExtension($extension) |
|
302 | |||
303 | /** |
||
304 | * create a new basename with a new extension |
||
305 | * |
||
306 | * @param string $basenamePart the basename file part |
||
307 | * @param string $extension the new extension to add |
||
308 | * @param string $parameterPart the basename parameter part |
||
309 | * |
||
310 | * @return string |
||
311 | */ |
||
312 | 51 | protected function buildBasename($basenamePart, $extension, $parameterPart) |
|
331 | |||
332 | /** |
||
333 | * validate and format the given extension |
||
334 | * |
||
335 | * @param string $extension the new extension to use |
||
336 | * |
||
337 | * @throws InvalidArgumentException If the extension is not valid |
||
338 | * |
||
339 | * @return string |
||
340 | */ |
||
341 | 63 | protected function formatExtension($extension) |
|
353 | } |
||
354 |