1 | <?php |
||
49 | class ItemList implements ItemListInterface |
||
50 | { |
||
51 | /** |
||
52 | * Items |
||
53 | * |
||
54 | * @var ItemInterface[] |
||
55 | */ |
||
56 | protected $items; |
||
57 | |||
58 | /** |
||
59 | * Internal pointer |
||
60 | * |
||
61 | * @var int |
||
62 | */ |
||
63 | protected $pointer; |
||
64 | |||
65 | /** |
||
66 | * ItemList constructor |
||
67 | * |
||
68 | * @param ItemInterface[] $items Items |
||
69 | * |
||
70 | * @api |
||
71 | */ |
||
72 | 16 | public function __construct(array $items = []) |
|
77 | |||
78 | /** |
||
79 | * Return the current item |
||
80 | * |
||
81 | * @return ItemInterface Item |
||
82 | * @api |
||
83 | */ |
||
84 | 2 | public function current() |
|
88 | |||
89 | /** |
||
90 | * Move forward to next element |
||
91 | * |
||
92 | * @return void |
||
93 | * @api |
||
94 | */ |
||
95 | 2 | public function next() |
|
99 | |||
100 | /** |
||
101 | * Return the position of the current element |
||
102 | * |
||
103 | * @return int Position of the current element |
||
104 | * @api |
||
105 | */ |
||
106 | 1 | public function key() |
|
110 | |||
111 | /** |
||
112 | * Checks if current position is valid |
||
113 | * |
||
114 | * @return boolean The current position is valid |
||
115 | * @api |
||
116 | */ |
||
117 | 2 | public function valid() |
|
121 | |||
122 | /** |
||
123 | * Rewind the item list to the first element |
||
124 | * |
||
125 | * @return void |
||
126 | * @api |
||
127 | */ |
||
128 | 2 | public function rewind() |
|
132 | |||
133 | /** |
||
134 | * Test if an offset exists |
||
135 | * |
||
136 | * @param int $offset Offset |
||
137 | * |
||
138 | * @return boolean Offset exists |
||
139 | * @api |
||
140 | */ |
||
141 | public function offsetExists($offset) |
||
145 | |||
146 | /** |
||
147 | * Return the item at a particular offset |
||
148 | * |
||
149 | * @param int $offset Offset |
||
150 | * |
||
151 | * @return ItemInterface Item |
||
152 | * @api |
||
153 | */ |
||
154 | 3 | public function offsetGet($offset) |
|
158 | |||
159 | /** |
||
160 | * Set an item at a particular offset |
||
161 | * |
||
162 | * @param int $offset Offset |
||
163 | * @param ItemInterface $value Item |
||
164 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
165 | * |
||
166 | * @api |
||
167 | */ |
||
168 | 1 | public function offsetSet($offset, $value) |
|
172 | |||
173 | /** |
||
174 | * Delete an item at a particular offset |
||
175 | * |
||
176 | * @param int $offset Offset |
||
177 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
178 | */ |
||
179 | 1 | public function offsetUnset($offset) |
|
183 | |||
184 | /** |
||
185 | * Return an object representation of the item list |
||
186 | * |
||
187 | * @return \stdClass Micro information items |
||
188 | */ |
||
189 | 1 | public function toObject() |
|
200 | |||
201 | /** |
||
202 | * Return the first item, optionally of particular types |
||
203 | * |
||
204 | * @param array ...$types Item types |
||
205 | * |
||
206 | * @return ItemInterface Item |
||
207 | * @throws OutOfBoundsException If there are no matching items |
||
208 | * @api |
||
209 | */ |
||
210 | 2 | public function getFirstItem(...$types) |
|
224 | |||
225 | /** |
||
226 | * Return all items as an array, optionally filtered by item type(s) |
||
227 | * |
||
228 | * @param array ...$types Item types |
||
229 | * |
||
230 | * @return ItemInterface[] Items matching the requested types |
||
231 | * @api |
||
232 | */ |
||
233 | 6 | public function getItems(...$types) |
|
247 | |||
248 | /** |
||
249 | * Return the number of items in this list |
||
250 | * |
||
251 | * @return int Number of items |
||
252 | * @api |
||
253 | */ |
||
254 | 2 | public function count() |
|
258 | |||
259 | /** |
||
260 | * Generic item getter |
||
261 | * |
||
262 | * @param string $type Item type |
||
263 | * @param array $arguments Arguments |
||
264 | * |
||
265 | * @return ItemInterface Item |
||
266 | * @throws InvalidArgumentException If the item index is invalid |
||
267 | * @api |
||
268 | */ |
||
269 | 2 | public function __call($type, $arguments) |
|
287 | |||
288 | /** |
||
289 | * Return an item by type and index |
||
290 | * |
||
291 | * @param string $type Item type |
||
292 | * @param int $index Item index |
||
293 | * |
||
294 | * @return ItemInterface Item |
||
295 | * @throws OutOfBoundsException If the item index is out of bounds |
||
296 | */ |
||
297 | 2 | protected function getItemByTypeAndIndex($type, $index) |
|
311 | } |
||
312 |