1 | <?php |
||
26 | abstract class AbstractHierarchicalComponent implements HierarchicalComponent |
||
27 | { |
||
28 | use ImmutableCollectionTrait; |
||
29 | |||
30 | use ImmutableComponentTrait; |
||
31 | |||
32 | const IS_ABSOLUTE = 1; |
||
33 | |||
34 | const IS_RELATIVE = 0; |
||
35 | |||
36 | /** |
||
37 | * Hierarchical component separator |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected static $separator; |
||
42 | |||
43 | /** |
||
44 | * Is the object considered absolute |
||
45 | * |
||
46 | * @var int |
||
47 | */ |
||
48 | protected $isAbsolute = self::IS_RELATIVE; |
||
49 | |||
50 | /** |
||
51 | * new instance |
||
52 | * |
||
53 | * @param null|string $str the component value |
||
54 | */ |
||
55 | abstract public function __construct($str); |
||
56 | |||
57 | /** |
||
58 | * Returns an instance with the specified string |
||
59 | * |
||
60 | * This method MUST retain the state of the current instance, and return |
||
61 | * an instance that contains the modified data |
||
62 | * |
||
63 | * @param string $value |
||
64 | * |
||
65 | * @return static |
||
66 | */ |
||
67 | 414 | public function modify($value) |
|
75 | |||
76 | /** |
||
77 | * Returns whether or not the component is absolute or not |
||
78 | * |
||
79 | * @return bool |
||
80 | */ |
||
81 | 27 | public function isAbsolute() |
|
85 | |||
86 | /** |
||
87 | * Return a new instance when needed |
||
88 | * |
||
89 | * @param array $data |
||
90 | * |
||
91 | * @return static |
||
92 | */ |
||
93 | 285 | protected function newCollectionInstance(array $data) |
|
101 | |||
102 | /** |
||
103 | * Returns the instance string representation |
||
104 | * with its optional URI delimiters |
||
105 | * |
||
106 | * @return string |
||
107 | */ |
||
108 | 652 | public function getUriComponent() |
|
112 | |||
113 | /** |
||
114 | * Returns an instance with the specified component prepended |
||
115 | * |
||
116 | * This method MUST retain the state of the current instance, and return |
||
117 | * an instance that contains the modified component with the prepended data |
||
118 | * |
||
119 | * @param HierarchicalComponent|string $component the component to prepend |
||
120 | * |
||
121 | * @return static |
||
122 | */ |
||
123 | 60 | public function prepend($component) |
|
130 | |||
131 | /** |
||
132 | * Returns an instance with the specified component appended |
||
133 | * |
||
134 | * This method MUST retain the state of the current instance, and return |
||
135 | * an instance that contains the modified component with the appended data |
||
136 | * |
||
137 | * @param HierarchicalComponent|string $component the component to append |
||
138 | * |
||
139 | * @return static |
||
140 | */ |
||
141 | abstract public function append($component); |
||
142 | |||
143 | /** |
||
144 | * Validate a component as a HierarchicalComponentInterface object |
||
145 | * |
||
146 | * @param HierarchicalComponent|string $component |
||
147 | * |
||
148 | * @return static |
||
149 | */ |
||
150 | 186 | protected function validateComponent($component) |
|
158 | |||
159 | /** |
||
160 | * return a new instance from an array or a traversable object |
||
161 | * |
||
162 | * @param \Traversable|string[] $data The segments list |
||
163 | * @param int $type one of the constant IS_ABSOLUTE or IS_RELATIVE |
||
164 | * |
||
165 | * @throws InvalidArgumentException If $type is not a recognized constant |
||
166 | * |
||
167 | * @return static |
||
168 | */ |
||
169 | 486 | public static function createFromArray($data, $type = self::IS_RELATIVE) |
|
179 | |||
180 | /** |
||
181 | * Return a formatted component string according to its type |
||
182 | * |
||
183 | * @param \Traversable|string[] $data The segments list |
||
184 | * @param int $type |
||
185 | * |
||
186 | * @throws InvalidArgumentException If $data is invalid |
||
187 | * |
||
188 | * @return string |
||
189 | */ |
||
190 | 336 | protected static function formatComponentString($data, $type) |
|
199 | |||
200 | /** |
||
201 | * Returns an instance with the modified segment |
||
202 | * |
||
203 | * This method MUST retain the state of the current instance, and return |
||
204 | * an instance that contains the modified component with the replaced data |
||
205 | * |
||
206 | * @param int $offset the label offset to remove and replace by |
||
207 | * the given component |
||
208 | * @param HierarchicalComponent|string $component the component added |
||
209 | * |
||
210 | * @return static |
||
211 | */ |
||
212 | 69 | public function replace($offset, $component) |
|
228 | } |
||
229 |