1 | <?php |
||
10 | class Collection implements \Iterator, \Countable { |
||
11 | |||
12 | protected $collection = []; |
||
13 | |||
14 | /** |
||
15 | * Add item to collection |
||
16 | * |
||
17 | * @param mixed $item |
||
18 | */ |
||
19 | 4 | public function add($item) { |
|
22 | |||
23 | /** |
||
24 | * Return the current item |
||
25 | * |
||
26 | * @return false|mixed Item |
||
27 | */ |
||
28 | 1 | public function current() { |
|
29 | 1 | $item = current($this->collection); |
|
30 | |||
31 | 1 | return $item; |
|
32 | } |
||
33 | |||
34 | /** |
||
35 | * Return the key of the current item |
||
36 | * |
||
37 | * @return mixed scalar on success, or null on failure. |
||
38 | */ |
||
39 | 1 | public function key() { |
|
40 | 1 | $key = key($this->collection); |
|
41 | |||
42 | 1 | return $key; |
|
43 | } |
||
44 | |||
45 | /** |
||
46 | * Move forward to next item |
||
47 | */ |
||
48 | 3 | public function next() { |
|
51 | |||
52 | /** |
||
53 | * Rewind the collection to the first item |
||
54 | */ |
||
55 | 2 | public function rewind() { |
|
60 | |||
61 | /** |
||
62 | * Checks if current position is valid |
||
63 | * |
||
64 | * @return bool Returns true on success or false on failure. |
||
65 | */ |
||
66 | 1 | public function valid() { |
|
72 | |||
73 | /** |
||
74 | * Count elements of items in collection |
||
75 | * |
||
76 | * @return int Count |
||
77 | */ |
||
78 | 1 | public function count() { |
|
83 | } |
||
84 |