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 whether or not the component is absolute or not |
||
59 | * |
||
60 | 16 | * @return bool |
|
61 | */ |
||
62 | 16 | public function isAbsolute() |
|
66 | |||
67 | /** |
||
68 | * Return a new instance when needed |
||
69 | * |
||
70 | * @param array $data |
||
71 | * |
||
72 | 190 | * @return static |
|
73 | */ |
||
74 | 190 | protected function newCollectionInstance(array $data) |
|
82 | |||
83 | /** |
||
84 | 414 | * Returns the instance string representation |
|
85 | * with its optional URI delimiters |
||
86 | 414 | * |
|
87 | * @return string |
||
88 | */ |
||
89 | public function getUriComponent() |
||
93 | |||
94 | 40 | /** |
|
95 | 40 | * Returns an instance with the specified component prepended |
|
96 | 40 | * |
|
97 | 40 | * This method MUST retain the state of the current instance, and return |
|
98 | * an instance that contains the modified component with the prepended data |
||
99 | * |
||
100 | * @param HierarchicalComponent|string $component the component to prepend |
||
101 | * |
||
102 | * @return static |
||
103 | */ |
||
104 | public function prepend($component) |
||
111 | |||
112 | 124 | /** |
|
113 | * Returns an instance with the specified component appended |
||
114 | 124 | * |
|
115 | 50 | * This method MUST retain the state of the current instance, and return |
|
116 | * an instance that contains the modified component with the appended data |
||
117 | * |
||
118 | 90 | * @param HierarchicalComponent|string $component the component to append |
|
119 | * |
||
120 | * @return static |
||
121 | */ |
||
122 | abstract public function append($component); |
||
123 | |||
124 | /** |
||
125 | * Validate a component as a HierarchicalComponentInterface object |
||
126 | * |
||
127 | * @param HierarchicalComponent|string $component |
||
128 | * |
||
129 | * @return static |
||
130 | */ |
||
131 | 314 | protected function validateComponent($component) |
|
139 | 310 | ||
140 | /** |
||
141 | * return a new instance from an array or a traversable object |
||
142 | * |
||
143 | * @param \Traversable|string[] $data The segments list |
||
144 | * @param int $type one of the constant IS_ABSOLUTE or IS_RELATIVE |
||
145 | * |
||
146 | * @throws InvalidArgumentException If $type is not a recognized constant |
||
147 | * |
||
148 | * @return static |
||
149 | */ |
||
150 | public static function createFromArray($data, $type = self::IS_RELATIVE) |
||
160 | |||
161 | /** |
||
162 | * Return a formatted component string according to its type |
||
163 | * |
||
164 | * @param \Traversable|string[] $data The segments list |
||
165 | 46 | * @param int $type |
|
166 | * |
||
167 | 46 | * @throws InvalidArgumentException If $data is invalid |
|
168 | 10 | * |
|
169 | * @return string |
||
170 | */ |
||
171 | 36 | protected static function formatComponentString($data, $type) |
|
180 | |||
181 | /** |
||
182 | * Returns an instance with the modified segment |
||
183 | * |
||
184 | * This method MUST retain the state of the current instance, and return |
||
185 | * an instance that contains the modified component with the replaced data |
||
186 | * |
||
187 | * @param int $offset the label offset to remove and replace by |
||
188 | * the given component |
||
189 | * @param HierarchicalComponent|string $component the component added |
||
190 | * |
||
191 | * @return static |
||
192 | */ |
||
193 | public function replace($offset, $component) |
||
209 | |||
210 | /** |
||
211 | * @inheritdoc |
||
212 | */ |
||
213 | public static function __set_state(array $properties) |
||
217 | } |
||
218 |