1 | <?php |
||
20 | abstract class AbstractObjectCollection extends AbstractObject implements ObjectCollectionInterface |
||
21 | { |
||
22 | /** |
||
23 | * The item instance class |
||
24 | */ |
||
25 | const ITEM_CLASS_INSTANCE = ObjectInterface::class; |
||
26 | |||
27 | /** |
||
28 | * A collection of items. |
||
29 | * |
||
30 | * @var array|\ArrayIterator |
||
31 | */ |
||
32 | protected $items = []; |
||
33 | |||
34 | /******************************************* |
||
35 | * ITEMS |
||
36 | *******************************************/ |
||
37 | |||
38 | /** |
||
39 | * Add an item to a collection |
||
40 | * |
||
41 | * @param $item |
||
42 | * @return static |
||
43 | * @throws InvalidCollectionItemException |
||
44 | */ |
||
45 | public function addItem($item) |
||
64 | |||
65 | /** |
||
66 | * @param array $items |
||
67 | * @return static |
||
68 | */ |
||
69 | public function setItems($items = []) |
||
84 | |||
85 | /** |
||
86 | * @param null $indexBy |
||
87 | * @return ObjectInterface[] |
||
88 | */ |
||
89 | public function getItems($indexBy = null) |
||
93 | |||
94 | /** |
||
95 | * @return \ArrayIterator |
||
96 | */ |
||
97 | public function getIterator(): \ArrayIterator |
||
107 | |||
108 | /** |
||
109 | * @return mixed|null |
||
110 | */ |
||
111 | public function getFirstItem() |
||
119 | |||
120 | |||
121 | /******************************************* |
||
122 | * MERGE |
||
123 | *******************************************/ |
||
124 | |||
125 | /** |
||
126 | * Merge one collection into another |
||
127 | * |
||
128 | * @param ObjectCollectionInterface $collection |
||
129 | * @return static |
||
130 | */ |
||
131 | public function merge(ObjectCollectionInterface $collection) |
||
140 | } |
||
141 |