1 | <?php |
||
18 | final class DataCollection implements DataCollectionInterface |
||
19 | { |
||
20 | use DataTrait; |
||
21 | |||
22 | const STORAGE_KEY = 'items'; |
||
23 | |||
24 | /** |
||
25 | * @var int |
||
26 | */ |
||
27 | private $position; |
||
28 | |||
29 | /** |
||
30 | * @param array $data |
||
31 | */ |
||
32 | public function __construct(array $data) |
||
40 | |||
41 | /** |
||
42 | * (PHP 5 >= 5.0.0)<br/> |
||
43 | * Return the current element |
||
44 | * @link http://php.net/manual/en/iterator.current.php |
||
45 | * @return mixed Can return any type. |
||
46 | */ |
||
47 | public function current() |
||
51 | |||
52 | /** |
||
53 | * (PHP 5 >= 5.0.0)<br/> |
||
54 | * Move forward to next element |
||
55 | * @link http://php.net/manual/en/iterator.next.php |
||
56 | * @return void Any returned value is ignored. |
||
57 | */ |
||
58 | public function next() |
||
62 | |||
63 | /** |
||
64 | * (PHP 5 >= 5.0.0)<br/> |
||
65 | * Return the key of the current element |
||
66 | * @link http://php.net/manual/en/iterator.key.php |
||
67 | * @return int scalar on success, or null on failure. |
||
68 | */ |
||
69 | public function key() |
||
73 | |||
74 | /** |
||
75 | * (PHP 5 >= 5.0.0)<br/> |
||
76 | * Checks if current position is valid |
||
77 | * @link http://php.net/manual/en/iterator.valid.php |
||
78 | * @return bool The return value will be casted to bool and then evaluated. |
||
79 | * Returns true on success or false on failure. |
||
80 | */ |
||
81 | public function valid() : bool |
||
85 | |||
86 | /** |
||
87 | * (PHP 5 >= 5.0.0)<br/> |
||
88 | * Rewind the Iterator to the first element |
||
89 | * @link http://php.net/manual/en/iterator.rewind.php |
||
90 | * @return void Any returned value is ignored. |
||
91 | */ |
||
92 | public function rewind() |
||
96 | |||
97 | /** |
||
98 | * Add element to store. |
||
99 | * |
||
100 | * @param mixed $item |
||
101 | * @param int $position |
||
102 | * @return $this |
||
103 | */ |
||
104 | public function addItem($item, $position = null) |
||
116 | |||
117 | /** |
||
118 | * Get element from store. |
||
119 | * |
||
120 | * @param int $position |
||
121 | * @return bool|mixed |
||
122 | */ |
||
123 | public function getItem(int $position = 0) |
||
127 | |||
128 | /** |
||
129 | * @return int |
||
130 | */ |
||
131 | public function count() : int |
||
135 | |||
136 | /** |
||
137 | * remove item from position |
||
138 | * be carefull: this also reindexes the array |
||
139 | * |
||
140 | * @param int $position |
||
141 | * @return $this |
||
142 | */ |
||
143 | public function removeItem(int $position) |
||
155 | } |
||
156 |