1 | <?php |
||
12 | class Collection implements ArrayAccess, Iterator |
||
13 | { |
||
14 | /** @var array */ |
||
15 | private $elements; |
||
16 | |||
17 | /** @var int */ |
||
18 | private $numberOfElements; |
||
19 | |||
20 | /** |
||
21 | * Collection constructor. |
||
22 | * @param array $elements |
||
23 | */ |
||
24 | public function __construct(array $elements = array()) |
||
28 | |||
29 | //begin of ArrayAccess interface implementation |
||
30 | /** |
||
31 | * Whether a offset exists |
||
32 | * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
||
33 | * @param mixed $offset <p> |
||
34 | * An offset to check for. |
||
35 | * </p> |
||
36 | * @return boolean true on success or false on failure. |
||
37 | * </p> |
||
38 | * <p> |
||
39 | * The return value will be casted to boolean if non-boolean was returned. |
||
40 | * @since 5.0.0 |
||
41 | */ |
||
42 | public function offsetExists($offset) |
||
46 | |||
47 | /** |
||
48 | * Offset to retrieve |
||
49 | * @link http://php.net/manual/en/arrayaccess.offsetget.php |
||
50 | * @param mixed $offset <p> |
||
51 | * The offset to retrieve. |
||
52 | * </p> |
||
53 | * @return mixed Can return all value types. |
||
54 | * @since 5.0.0 |
||
55 | */ |
||
56 | public function offsetGet($offset) |
||
64 | |||
65 | /** |
||
66 | * Offset to set |
||
67 | * @link http://php.net/manual/en/arrayaccess.offsetset.php |
||
68 | * @param mixed $offset <p> |
||
69 | * The offset to assign the value to. |
||
70 | * </p> |
||
71 | * @param mixed $value <p> |
||
72 | * The value to set. |
||
73 | * </p> |
||
74 | * @return void |
||
75 | * @since 5.0.0 |
||
76 | */ |
||
77 | public function offsetSet($offset, $value) |
||
86 | |||
87 | /** |
||
88 | * Offset to unset |
||
89 | * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
||
90 | * @param mixed $offset <p> |
||
91 | * The offset to unset. |
||
92 | * </p> |
||
93 | * @return void |
||
94 | * @since 5.0.0 |
||
95 | */ |
||
96 | public function offsetUnset($offset) |
||
103 | //end of ArrayAccess interface implementation |
||
104 | |||
105 | //begin of Iterator interface implementation |
||
106 | /** |
||
107 | * Return the current element |
||
108 | * @link http://php.net/manual/en/iterator.current.php |
||
109 | * @return mixed Can return any type. |
||
110 | * @since 5.0.0 |
||
111 | */ |
||
112 | public function current() |
||
116 | |||
117 | /** |
||
118 | * Move forward to next element |
||
119 | * @link http://php.net/manual/en/iterator.next.php |
||
120 | * @return void Any returned value is ignored. |
||
121 | * @since 5.0.0 |
||
122 | */ |
||
123 | public function next() |
||
127 | |||
128 | /** |
||
129 | * Return the key of the current element |
||
130 | * @link http://php.net/manual/en/iterator.key.php |
||
131 | * @return mixed scalar on success, or null on failure. |
||
132 | * @since 5.0.0 |
||
133 | */ |
||
134 | public function key() |
||
138 | |||
139 | /** |
||
140 | * Checks if current position is valid |
||
141 | * @link http://php.net/manual/en/iterator.valid.php |
||
142 | * @return boolean The return value will be casted to boolean and then evaluated. |
||
143 | * Returns true on success or false on failure. |
||
144 | * @since 5.0.0 |
||
145 | */ |
||
146 | public function valid() |
||
150 | |||
151 | /** |
||
152 | * Rewind the Iterator to the first element |
||
153 | * @link http://php.net/manual/en/iterator.rewind.php |
||
154 | * @return void Any returned value is ignored. |
||
155 | * @since 5.0.0 |
||
156 | */ |
||
157 | public function rewind() |
||
161 | //end of Iterator interface implementation |
||
162 | |||
163 | /** |
||
164 | * @param array $elements |
||
165 | * @param bool $referenceKeysOfProvidedElements |
||
166 | * @throws InvalidArgumentException |
||
167 | */ |
||
168 | public function addMany(array $elements, $referenceKeysOfProvidedElements = false) |
||
180 | |||
181 | /** |
||
182 | * @param mixed $element |
||
183 | * @param mixed|null $key |
||
184 | * @throws InvalidArgumentException |
||
185 | */ |
||
186 | public function addOne($element, $key = null) |
||
196 | |||
197 | /** |
||
198 | * @param mixed $key |
||
199 | * @return bool |
||
200 | */ |
||
201 | public function containsKey($key) |
||
205 | |||
206 | /** |
||
207 | * @param mixed $value |
||
208 | * @return bool |
||
209 | */ |
||
210 | public function containsValue($value) |
||
214 | |||
215 | /** |
||
216 | * @return int |
||
217 | */ |
||
218 | public function getNumberOfElements() |
||
222 | |||
223 | /** |
||
224 | * @param null|mixed $key |
||
225 | * @return mixed |
||
226 | */ |
||
227 | public function getOne($key = null) |
||
235 | |||
236 | /** |
||
237 | * @return bool |
||
238 | */ |
||
239 | public function isEmpty() |
||
243 | |||
244 | /** |
||
245 | * @return array |
||
246 | */ |
||
247 | public function convertToArray() |
||
261 | |||
262 | /** |
||
263 | * @param string $separator |
||
264 | * @return string |
||
265 | */ |
||
266 | public function convertToString($separator = ' ') |
||
270 | |||
271 | /** |
||
272 | * @param array $elements |
||
273 | * @throws InvalidArgumentException |
||
274 | */ |
||
275 | public function resetAll(array $elements) |
||
286 | |||
287 | /** |
||
288 | * @return string |
||
289 | */ |
||
290 | public function __toString() |
||
294 | |||
295 | /** |
||
296 | * overwrite this if you want to, default is always returning a true |
||
297 | * @param mixed $element |
||
298 | * @return bool |
||
299 | */ |
||
300 | protected function elementIsValid($element) |
||
304 | |||
305 | private function calculateNumberOfElements() |
||
309 | |||
310 | private function reset() |
||
315 | } |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.