1 | <?php |
||
9 | abstract class Collection implements \Iterator, \Countable |
||
10 | { |
||
11 | /** |
||
12 | * @var array Collection Entities |
||
13 | */ |
||
14 | protected $items = []; |
||
15 | /** |
||
16 | * @var string Current index of the collection |
||
17 | */ |
||
18 | protected $current; |
||
19 | |||
20 | /** |
||
21 | * Init the collection |
||
22 | */ |
||
23 | 11 | public function __construct() |
|
28 | |||
29 | /** |
||
30 | * Rewind |
||
31 | */ |
||
32 | 2 | public function rewind() |
|
37 | |||
38 | /** |
||
39 | * Get the current element |
||
40 | * |
||
41 | * @return mixed |
||
42 | */ |
||
43 | 2 | public function current() |
|
47 | |||
48 | /** |
||
49 | * Get the current key |
||
50 | * |
||
51 | * @return string |
||
52 | */ |
||
53 | 1 | public function key() |
|
57 | |||
58 | /** |
||
59 | * Next |
||
60 | */ |
||
61 | 2 | public function next() |
|
66 | |||
67 | /** |
||
68 | * Check if current element exists |
||
69 | * |
||
70 | * @return bool |
||
71 | */ |
||
72 | 2 | public function valid() |
|
76 | |||
77 | /** |
||
78 | * Get total number of collection elements |
||
79 | * |
||
80 | * @return int |
||
81 | */ |
||
82 | 6 | public function count() |
|
86 | |||
87 | /** |
||
88 | * Check if element exists |
||
89 | * |
||
90 | * @param string $key Element key |
||
91 | * |
||
92 | * @return bool |
||
93 | */ |
||
94 | 6 | public function has($key) |
|
98 | |||
99 | /** |
||
100 | * Add an item to the collection |
||
101 | * |
||
102 | * @param mixed $item Item |
||
103 | * @param string $key Item key |
||
104 | */ |
||
105 | 10 | public function add($item, $key = null) |
|
113 | |||
114 | /** |
||
115 | * Delete item from collection |
||
116 | * |
||
117 | * @param string $key Item key |
||
118 | */ |
||
119 | 2 | public function del($key) |
|
125 | |||
126 | /** |
||
127 | * Get item from collection |
||
128 | * |
||
129 | * @param string $key Item key |
||
130 | * |
||
131 | * @return null|mixed Collection item |
||
132 | */ |
||
133 | 6 | public function get($key) |
|
137 | } |
||
138 |