1 | <?php |
||
48 | class ItemList extends Collection implements ItemListInterface |
||
49 | { |
||
50 | /** |
||
51 | * Items |
||
52 | * |
||
53 | * @var ItemInterface[] |
||
54 | */ |
||
55 | protected $items; |
||
56 | |||
57 | /** |
||
58 | * Internal pointer |
||
59 | * |
||
60 | * @var int |
||
61 | */ |
||
62 | protected $pointer; |
||
63 | |||
64 | /** |
||
65 | * ItemList constructor |
||
66 | * |
||
67 | * @param ItemInterface[] $items Items |
||
68 | * |
||
69 | * @api |
||
70 | */ |
||
71 | 22 | public function __construct(array $items = []) |
|
76 | |||
77 | /** |
||
78 | * Return the current item |
||
79 | * |
||
80 | * @return ItemInterface Item |
||
81 | * @api |
||
82 | */ |
||
83 | 1 | public function current() |
|
87 | |||
88 | /** |
||
89 | * Move forward to next element |
||
90 | * |
||
91 | * @return void |
||
92 | * @api |
||
93 | */ |
||
94 | 1 | public function next() |
|
98 | |||
99 | /** |
||
100 | * Return the position of the current element |
||
101 | * |
||
102 | * @return int Position of the current element |
||
103 | * @api |
||
104 | */ |
||
105 | public function key() |
||
106 | { |
||
107 | return $this->pointer; |
||
108 | } |
||
109 | |||
110 | /** |
||
111 | * Checks if current position is valid |
||
112 | * |
||
113 | * @return boolean The current position is valid |
||
114 | * @api |
||
115 | */ |
||
116 | 1 | public function valid() |
|
120 | |||
121 | /** |
||
122 | * Rewind the item list to the first element |
||
123 | * |
||
124 | * @return void |
||
125 | * @api |
||
126 | */ |
||
127 | 1 | public function rewind() |
|
131 | |||
132 | /** |
||
133 | * Test if an offset exists |
||
134 | * |
||
135 | * @param int $offset Offset |
||
136 | * |
||
137 | * @return boolean Offset exists |
||
138 | * @api |
||
139 | */ |
||
140 | public function offsetExists($offset) |
||
144 | |||
145 | /** |
||
146 | * Return the item at a particular offset |
||
147 | * |
||
148 | * @param int $offset Offset |
||
149 | * |
||
150 | * @return ItemInterface Item |
||
151 | * @api |
||
152 | */ |
||
153 | 5 | public function offsetGet($offset) |
|
157 | |||
158 | /** |
||
159 | * Set an item at a particular offset |
||
160 | * |
||
161 | * @param int $offset Offset |
||
162 | * @param ItemInterface $value Item |
||
163 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
164 | * |
||
165 | * @api |
||
166 | */ |
||
167 | 1 | public function offsetSet($offset, $value) |
|
171 | |||
172 | /** |
||
173 | * Delete an item at a particular offset |
||
174 | * |
||
175 | * @param int $offset Offset |
||
176 | * @SuppressWarnings(PHPMD.UnusedFormalParameter) |
||
177 | */ |
||
178 | 1 | public function offsetUnset($offset) |
|
182 | |||
183 | /** |
||
184 | * Return an object representation of the item list |
||
185 | * |
||
186 | * @return \stdClass Micro information items |
||
187 | */ |
||
188 | 1 | public function toObject() |
|
199 | |||
200 | /** |
||
201 | * Return the first item, optionally of particular types |
||
202 | * |
||
203 | * @param array ...$types Item types |
||
204 | * |
||
205 | * @return ItemInterface Item |
||
206 | * @throws OutOfBoundsException If there are no matching items |
||
207 | * @api |
||
208 | */ |
||
209 | 5 | public function getFirstItem(...$types) |
|
223 | |||
224 | /** |
||
225 | * Return all items as an array, optionally filtered by item type(s) |
||
226 | * |
||
227 | * @param array ...$types Item types |
||
228 | * |
||
229 | * @return ItemInterface[] Items matching the requested types |
||
230 | * @api |
||
231 | */ |
||
232 | 12 | public function getItems(...$types) |
|
246 | |||
247 | /** |
||
248 | * Return the number of items in this list |
||
249 | * |
||
250 | * @return int Number of items |
||
251 | * @api |
||
252 | */ |
||
253 | 3 | public function count() |
|
257 | } |
||
258 |