1 | <?php |
||
5 | abstract class IndexedByPrimitiveCollection implements Collection |
||
6 | { |
||
7 | /** |
||
8 | * @var array |
||
9 | */ |
||
10 | protected $all_items; |
||
11 | |||
12 | /** |
||
13 | * @param array $some_items |
||
14 | */ |
||
15 | public function __construct(array $some_items = []) |
||
23 | |||
24 | private function validateItemClass($an_item) |
||
34 | |||
35 | private function validateCollectionClass(Collection $a_collection) |
||
46 | |||
47 | public function implode($glue = ',') |
||
51 | |||
52 | // Methods to set, unset and get items. |
||
53 | |||
54 | final public function setItemByKey($an_item_key, $an_item) |
||
60 | |||
61 | final public function unsetItemByKey($an_item_key) |
||
67 | |||
68 | final public function addItem($an_item) |
||
76 | |||
77 | final public function itemsIndexes() |
||
81 | |||
82 | final public function itemWithKey($an_item_key) |
||
92 | |||
93 | final public function allItems() |
||
97 | |||
98 | final public function hasItemWithKey($an_item_key) |
||
102 | |||
103 | // Set theory methods. |
||
104 | |||
105 | public function union(Collection $a_collection) |
||
113 | |||
114 | // Iterator methods. |
||
115 | |||
116 | final public function current() |
||
120 | |||
121 | final public function next() |
||
125 | |||
126 | final public function key() |
||
130 | |||
131 | final public function valid() |
||
135 | |||
136 | final public function rewind() |
||
140 | |||
141 | final public function count() |
||
145 | |||
146 | // Methods to override. |
||
147 | |||
148 | /** |
||
149 | * @return string The namespace of the class of each item contained in the {@see $all_items} array. Use the '::class' keyword. |
||
150 | */ |
||
151 | abstract protected function collectionItemsClassName(); |
||
152 | |||
153 | /** |
||
154 | * You can override this method and it'll be called each time you add an item through the {@see addItem} method. |
||
155 | * It returns the next array index by default. |
||
156 | * |
||
157 | * @param mixed $an_item Item of the {@see collectionItemsClassName} class. |
||
158 | * |
||
159 | * @return integer|string the collection key to insert the {@see $an_item} |
||
160 | */ |
||
161 | abstract protected function nextItemKey($an_item); |
||
162 | } |
||
163 |