1 | <?php |
||
27 | class ReferenceList implements Comparable, Countable, IteratorAggregate { |
||
28 | |||
29 | /** |
||
30 | * @var Reference[] |
||
31 | */ |
||
32 | private $references = array(); |
||
33 | |||
34 | 29 | /** |
|
35 | 29 | * @param Reference[]|Traversable $references |
|
36 | 8 | * |
|
37 | * @throws InvalidArgumentException |
||
38 | */ |
||
39 | 21 | public function __construct( $references = array() ) { |
|
52 | |||
53 | /** |
||
54 | * Adds the provided reference to the list. |
||
55 | * Empty references are ignored. |
||
56 | * |
||
57 | * @since 0.1 |
||
58 | 14 | * |
|
59 | 14 | * @param Reference $reference |
|
60 | * @param int|null $index |
||
61 | * |
||
62 | * @throws InvalidArgumentException |
||
63 | 14 | */ |
|
64 | public function addReference( Reference $reference, $index = null ) { |
||
80 | 14 | ||
81 | 14 | /** |
|
82 | * @since 1.1 |
||
83 | * |
||
84 | * @param Snak[]|Snak $snaks |
||
85 | * @param Snak [$snak2,...] |
||
86 | * |
||
87 | * @throws InvalidArgumentException |
||
88 | */ |
||
89 | public function addNewReference( $snaks = array() /*...*/ ) { |
||
96 | 6 | ||
97 | 5 | /** |
|
98 | * @param Reference $reference |
||
99 | * @param int $index |
||
100 | */ |
||
101 | private function insertReferenceAtIndex( Reference $reference, $index ) { |
||
104 | 2 | ||
105 | 2 | /** |
|
106 | * Returns if the list contains a reference with the same hash as the provided reference. |
||
107 | * |
||
108 | 2 | * @since 0.1 |
|
109 | 2 | * |
|
110 | 2 | * @param Reference $reference |
|
111 | 2 | * |
|
112 | 2 | * @return boolean |
|
113 | */ |
||
114 | 2 | public function hasReference( Reference $reference ) { |
|
117 | |||
118 | /** |
||
119 | 2 | * Returns the index of a reference or false if the reference could not be found. |
|
120 | * |
||
121 | 2 | * @since 0.5 |
|
122 | 2 | * |
|
123 | 2 | * @param Reference $reference |
|
124 | 2 | * |
|
125 | * @return int|boolean |
||
126 | */ |
||
127 | public function indexOf( Reference $reference ) { |
||
136 | 6 | ||
137 | 6 | /** |
|
138 | * Removes the reference with the same hash as the provided reference if such a reference exists in the list. |
||
139 | * |
||
140 | * @since 0.1 |
||
141 | * |
||
142 | * @param Reference $reference |
||
143 | */ |
||
144 | public function removeReference( Reference $reference ) { |
||
147 | |||
148 | /** |
||
149 | 2 | * Returns if the list contains a reference with the provided hash. |
|
150 | 2 | * |
|
151 | * @since 0.3 |
||
152 | 2 | * |
|
153 | 1 | * @param string $referenceHash |
|
154 | 1 | * |
|
155 | * @return boolean |
||
156 | 1 | */ |
|
157 | 2 | public function hasReferenceHash( $referenceHash ) { |
|
160 | |||
161 | /** |
||
162 | * Removes the reference with the provided hash if it exists in the list. |
||
163 | * |
||
164 | * @since 0.3 |
||
165 | * |
||
166 | * @param string $referenceHash ` |
||
167 | */ |
||
168 | public function removeReferenceHash( $referenceHash ) { |
||
175 | |||
176 | /** |
||
177 | * @param int $index |
||
178 | */ |
||
179 | private function removeReferenceAtIndex( $index ) { |
||
182 | 8 | ||
183 | 8 | /** |
|
184 | * Returns the reference with the provided hash, or |
||
185 | * null if there is no such reference in the list. |
||
186 | * |
||
187 | * @since 0.3 |
||
188 | * |
||
189 | * @param string $referenceHash |
||
190 | * |
||
191 | * @return Reference|null |
||
192 | */ |
||
193 | 5 | public function getReference( $referenceHash ) { |
|
202 | |||
203 | /** |
||
204 | * @see Serializable::serialize |
||
205 | * |
||
206 | * @since 2.1 |
||
207 | * |
||
208 | * @return string |
||
209 | */ |
||
210 | 14 | public function serialize() { |
|
213 | |||
214 | 14 | /** |
|
215 | 10 | * @see Serializable::unserialize |
|
216 | 10 | * |
|
217 | * @since 2.1 |
||
218 | 9 | * |
|
219 | * @param string $data |
||
220 | 9 | */ |
|
221 | public function unserialize( $data ) { |
||
224 | |||
225 | /** |
||
226 | * @since 4.4 |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | 3 | public function isEmpty() { |
|
233 | |||
234 | /** |
||
235 | * The hash is purely valuer based. Order of the elements in the array is not held into account. |
||
236 | * |
||
237 | * @since 0.3 |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | 3 | public function getValueHash() { |
|
245 | |||
246 | /** |
||
247 | * @see Comparable::equals |
||
248 | * |
||
249 | * The comparison is done purely value based, ignoring the order of the elements in the array. |
||
250 | 3 | * |
|
251 | 3 | * @since 0.3 |
|
252 | * |
||
253 | * @param mixed $target |
||
254 | * |
||
255 | * @return bool |
||
256 | */ |
||
257 | public function equals( $target ) { |
||
265 | |||
266 | /** |
||
267 | * @see Countable::count |
||
268 | * |
||
269 | * @return int |
||
270 | */ |
||
271 | public function count() { |
||
274 | |||
275 | /** |
||
276 | * @see IteratorAggregate::getIterator |
||
277 | * |
||
278 | * @since 5.0 |
||
279 | * |
||
280 | * @return Traversable |
||
281 | */ |
||
282 | public function getIterator() { |
||
285 | |||
286 | /** |
||
287 | * @since 5.0 |
||
288 | * |
||
289 | * @return Reference[] |
||
290 | */ |
||
291 | public function toArray() { |
||
294 | |||
295 | } |
||
296 |