1 | <?php |
||
14 | class Collection implements CollectionInterface |
||
15 | { |
||
16 | /** |
||
17 | * Collection's identifier. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $id; |
||
22 | |||
23 | /** |
||
24 | * Collection's items. |
||
25 | * |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $items = []; |
||
29 | |||
30 | /** |
||
31 | * Collection constructor. |
||
32 | * |
||
33 | * @param string $id |
||
34 | * @param array $items |
||
35 | */ |
||
36 | public function __construct($id, $items = []) |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | public function setId(string $id): BaseInterface |
||
51 | |||
52 | /** |
||
53 | * {@inheritdoc} |
||
54 | */ |
||
55 | public function getId(): string |
||
59 | |||
60 | /** |
||
61 | * Search item by ID. |
||
62 | * |
||
63 | * @param string $id |
||
64 | * |
||
65 | * @return array|null |
||
66 | */ |
||
67 | protected function searchItem(string $id): ?array |
||
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | public function has(string $id): bool |
||
86 | |||
87 | /** |
||
88 | * {@inheritdoc} |
||
89 | */ |
||
90 | public function add(ItemInterface $item): CollectionInterface |
||
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | public function replace(string $id, ItemInterface $item): CollectionInterface |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function remove(string $id): CollectionInterface |
||
137 | |||
138 | /** |
||
139 | * {@inheritdoc} |
||
140 | */ |
||
141 | public function get(string $id): ItemInterface |
||
153 | |||
154 | /** |
||
155 | * {@inheritdoc} |
||
156 | */ |
||
157 | public function getPosition(string $id): int |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | public function keys(): array |
||
179 | |||
180 | /** |
||
181 | * {@inheritdoc} |
||
182 | */ |
||
183 | public function first(): ?ItemInterface |
||
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | public function last(): ?ItemInterface |
||
205 | |||
206 | /** |
||
207 | * {@inheritdoc} |
||
208 | */ |
||
209 | public function count(): int |
||
213 | |||
214 | /** |
||
215 | * {@inheritdoc} |
||
216 | */ |
||
217 | public function toArray(): array |
||
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | public function toJson(): string |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | public function getIterator(): \ArrayIterator |
||
237 | |||
238 | /** |
||
239 | * {@inheritdoc} |
||
240 | */ |
||
241 | public function usort(\Closure $callback = null): CollectionInterface |
||
253 | |||
254 | /** |
||
255 | * {@inheritdoc} |
||
256 | */ |
||
257 | public function filter(\Closure $callback): CollectionInterface |
||
261 | |||
262 | /** |
||
263 | * {@inheritdoc} |
||
264 | */ |
||
265 | public function map(\Closure $callback): CollectionInterface |
||
269 | |||
270 | /** |
||
271 | * Implement ArrayAccess. |
||
272 | * |
||
273 | * @param string $offset |
||
274 | * |
||
275 | * @return bool |
||
276 | */ |
||
277 | public function offsetExists($offset) |
||
281 | |||
282 | /** |
||
283 | * Implement ArrayAccess. |
||
284 | * |
||
285 | * @param string $offset |
||
286 | * |
||
287 | * @return CollectionInterface|ItemInterface|null |
||
288 | */ |
||
289 | public function offsetGet($offset) |
||
293 | |||
294 | /** |
||
295 | * Implement ArrayAccess. |
||
296 | * |
||
297 | * @param mixed $offset |
||
298 | * @param ItemInterface $value |
||
299 | * |
||
300 | * @return CollectionInterface|ItemInterface|null |
||
301 | */ |
||
302 | public function offsetSet($offset, $value) |
||
306 | |||
307 | /** |
||
308 | * Implement ArrayAccess. |
||
309 | * |
||
310 | * @param string $offset |
||
311 | * |
||
312 | * @return CollectionInterface|null |
||
313 | */ |
||
314 | public function offsetUnset($offset) |
||
318 | |||
319 | /** |
||
320 | * Return collection ID. |
||
321 | * |
||
322 | * @return string |
||
323 | */ |
||
324 | public function __toString() |
||
328 | } |
||
329 |