1 | <?php |
||
16 | class Collection implements Countable, Iterator, Serializes { |
||
17 | /** |
||
18 | * Collection elements. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $elements = array(); |
||
23 | |||
24 | /** |
||
25 | * Collection configuration. |
||
26 | * |
||
27 | * @var array |
||
28 | */ |
||
29 | protected $config = array(); |
||
30 | |||
31 | /** |
||
32 | * Models registered to the collection. |
||
33 | * |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $model; |
||
37 | |||
38 | /** |
||
39 | * Where Collection is in loop. |
||
40 | * |
||
41 | * @var int |
||
42 | */ |
||
43 | protected $position = 0; |
||
44 | |||
45 | /** |
||
46 | * Collection constructor. |
||
47 | * |
||
48 | * @param array $elements |
||
49 | * @param array $config |
||
50 | */ |
||
51 | 60 | public function __construct( array $elements = array(), array $config = array() ) { |
|
58 | |||
59 | /** |
||
60 | * Adds a new element to the Collection. |
||
61 | * |
||
62 | * @param mixed $element |
||
63 | * |
||
64 | * @throws RuntimeException |
||
65 | */ |
||
66 | 27 | public function add( $element ) { |
|
77 | |||
78 | /** |
||
79 | * Removes an element by index or value. |
||
80 | * |
||
81 | * @param mixed $index |
||
82 | * |
||
83 | * @return $this |
||
84 | */ |
||
85 | public function remove( $index ) { |
||
102 | |||
103 | /** |
||
104 | * Fetches the element at the provided index. |
||
105 | * |
||
106 | * @param int $index |
||
107 | * |
||
108 | * @return mixed |
||
109 | */ |
||
110 | 12 | public function at( $index ) { |
|
113 | |||
114 | /** |
||
115 | * Maps over the Collection's elements, |
||
116 | * |
||
117 | * @param callable $callback |
||
118 | * |
||
119 | * @return Collection |
||
120 | */ |
||
121 | protected function map( callable $callback ) { |
||
124 | |||
125 | /** |
||
126 | * Filters the Collection's elements. |
||
127 | * |
||
128 | * @param callable $callback |
||
129 | * |
||
130 | * @return Collection |
||
131 | */ |
||
132 | public function filter( callable $callback ) { |
||
135 | |||
136 | /** |
||
137 | * {@inheritDoc} |
||
138 | * |
||
139 | * @return array |
||
140 | */ |
||
141 | public function serialize() { |
||
150 | |||
151 | /** |
||
152 | * Return the current element. |
||
153 | * |
||
154 | * @return mixed |
||
155 | */ |
||
156 | 3 | public function current() { |
|
159 | |||
160 | /** |
||
161 | * Move forward to next element. |
||
162 | */ |
||
163 | 3 | public function next() { |
|
166 | |||
167 | /** |
||
168 | * Return the key of the current element. |
||
169 | * |
||
170 | * @return mixed |
||
171 | */ |
||
172 | 3 | public function key() { |
|
175 | |||
176 | /** |
||
177 | * Checks if current position is valid. |
||
178 | * |
||
179 | * @return bool |
||
180 | */ |
||
181 | 3 | public function valid() { |
|
184 | |||
185 | /** |
||
186 | * Rewind the Iterator to the first element. |
||
187 | */ |
||
188 | 3 | public function rewind() { |
|
191 | |||
192 | /** |
||
193 | * Count elements of an object. |
||
194 | * |
||
195 | * @return int |
||
196 | */ |
||
197 | 6 | public function count() { |
|
200 | |||
201 | /** |
||
202 | * Parses the Collection config to set its properties. |
||
203 | * |
||
204 | * @param array $config |
||
205 | * |
||
206 | * @throws LogicException |
||
207 | */ |
||
208 | 60 | protected function parse_config( array $config ) { |
|
219 | } |
||
220 |