1 | <?php |
||
24 | class HierarchicalPath extends AbstractHierarchicalComponent implements HierarchicalPathInterface |
||
25 | { |
||
26 | use PathTrait; |
||
27 | |||
28 | /** |
||
29 | * @inheritdoc |
||
30 | */ |
||
31 | protected static $separator = '/'; |
||
32 | |||
33 | /** |
||
34 | * @inheritdoc |
||
35 | */ |
||
36 | protected static $invalidCharactersRegex = ',[?#],'; |
||
37 | |||
38 | /** |
||
39 | * New Instance |
||
40 | * |
||
41 | * @param string $path |
||
42 | */ |
||
43 | 904 | public function __construct($path = '') |
|
64 | |||
65 | /** |
||
66 | * validate the submitted data |
||
67 | * |
||
68 | * @param string $data |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | protected function validate($data) |
||
82 | |||
83 | /** |
||
84 | * Retrieves a single path segment. |
||
85 | * |
||
86 | * Retrieves a single path segment. If the segment offset has not been set, |
||
87 | * returns the default value provided. |
||
88 | * |
||
89 | * @param string $offset the segment offset |
||
90 | * @param mixed $default Default value to return if the offset does not exist. |
||
91 | * |
||
92 | * @return mixed |
||
93 | */ |
||
94 | 9 | public function getSegment($offset, $default = null) |
|
102 | |||
103 | /** |
||
104 | * @inheritdoc |
||
105 | */ |
||
106 | 9 | public static function __set_state(array $properties) |
|
110 | |||
111 | /** |
||
112 | * @inheritdoc |
||
113 | */ |
||
114 | 856 | public function __toString() |
|
123 | |||
124 | /** |
||
125 | * Returns an instance with the specified component appended |
||
126 | * |
||
127 | * This method MUST retain the state of the current instance, and return |
||
128 | * an instance that contains the modified component with the appended data |
||
129 | * |
||
130 | * @param HierarchicalComponent|string $component the component to append |
||
131 | * |
||
132 | * @return static |
||
133 | */ |
||
134 | 72 | public function append($component) |
|
146 | |||
147 | /** |
||
148 | * Returns the path basename |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | 63 | public function getBasename() |
|
158 | |||
159 | /** |
||
160 | * Returns parent directory's path |
||
161 | * |
||
162 | * @return string |
||
163 | */ |
||
164 | 24 | public function getDirname() |
|
172 | |||
173 | /** |
||
174 | * Returns the basename extension |
||
175 | * |
||
176 | * @return string |
||
177 | */ |
||
178 | 57 | public function getExtension() |
|
184 | |||
185 | /** |
||
186 | * Returns an instance with the specified basename extension |
||
187 | * |
||
188 | * This method MUST retain the state of the current instance, and return |
||
189 | * an instance that contains the extension basename modified. |
||
190 | * |
||
191 | * @param string $extension the new extension |
||
192 | * can preceeded with or without the dot (.) character |
||
193 | * |
||
194 | * @throws InvalidArgumentException If the extension is invalid |
||
195 | * |
||
196 | * @return static |
||
197 | */ |
||
198 | 63 | public function withExtension($extension) |
|
217 | |||
218 | /** |
||
219 | * create a new basename with a new extension |
||
220 | * |
||
221 | * @param string $basenamePart the basename file part |
||
222 | * @param string $extension the new extension to add |
||
223 | * @param string $parameterPart the basename parameter part |
||
224 | * |
||
225 | * @return string |
||
226 | */ |
||
227 | 51 | protected function buildBasename($basenamePart, $extension, $parameterPart) |
|
246 | |||
247 | /** |
||
248 | * validate and format the given extension |
||
249 | * |
||
250 | * @param string $extension the new extension to use |
||
251 | * |
||
252 | * @throws InvalidArgumentException If the extension is not valid |
||
253 | * |
||
254 | * @return string |
||
255 | */ |
||
256 | 63 | protected function formatExtension($extension) |
|
268 | } |
||
269 |