1 | <?php |
||
15 | class Collection implements ArrayAccess, Countable, IteratorAggregate, JsonSerializable, Serializable |
||
16 | { |
||
17 | /** |
||
18 | * The collection data. |
||
19 | * |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $items = []; |
||
23 | |||
24 | /** |
||
25 | * set data. |
||
26 | * |
||
27 | * @param mixed $items |
||
28 | */ |
||
29 | public function __construct(array $items = []) |
||
35 | |||
36 | /** |
||
37 | * Return all items. |
||
38 | * |
||
39 | * @return array |
||
40 | */ |
||
41 | public function all() |
||
45 | |||
46 | /** |
||
47 | * Return specific items. |
||
48 | * |
||
49 | * @param array $keys |
||
50 | * |
||
51 | * @return array |
||
52 | */ |
||
53 | public function only(array $keys) |
||
67 | |||
68 | /** |
||
69 | * Get all items except for those with the specified keys. |
||
70 | * |
||
71 | * @param mixed $keys |
||
72 | * |
||
73 | * @return static |
||
74 | */ |
||
75 | public function except($keys) |
||
81 | |||
82 | /** |
||
83 | * Merge data. |
||
84 | * |
||
85 | * @param Collection|array $items |
||
86 | * |
||
87 | * @return array |
||
88 | */ |
||
89 | public function merge($items) |
||
97 | |||
98 | /** |
||
99 | * To determine Whether the specified element exists. |
||
100 | * |
||
101 | * @param string $key |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function has($key) |
||
109 | |||
110 | /** |
||
111 | * Retrieve the first item. |
||
112 | * |
||
113 | * @return mixed |
||
114 | */ |
||
115 | public function first() |
||
119 | |||
120 | /** |
||
121 | * Retrieve the last item. |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function last() |
||
133 | |||
134 | /** |
||
135 | * add the item value. |
||
136 | * |
||
137 | * @param string $key |
||
138 | * @param mixed $value |
||
139 | */ |
||
140 | public function add($key, $value) |
||
144 | |||
145 | /** |
||
146 | * Set the item value. |
||
147 | * |
||
148 | * @param string $key |
||
149 | * @param mixed $value |
||
150 | */ |
||
151 | public function set($key, $value) |
||
155 | |||
156 | /** |
||
157 | * Retrieve item from Collection. |
||
158 | * |
||
159 | * @param string $key |
||
160 | * @param mixed $default |
||
161 | * |
||
162 | * @return mixed |
||
163 | */ |
||
164 | public function get($key, $default = null) |
||
168 | |||
169 | /** |
||
170 | * Remove item form Collection. |
||
171 | * |
||
172 | * @param string $key |
||
173 | */ |
||
174 | public function forget($key) |
||
178 | |||
179 | /** |
||
180 | * Build to array. |
||
181 | * |
||
182 | * @return array |
||
183 | */ |
||
184 | public function toArray() |
||
188 | |||
189 | /** |
||
190 | * Build to json. |
||
191 | * |
||
192 | * @param int $option |
||
193 | * |
||
194 | * @return string |
||
195 | */ |
||
196 | public function toJson($option = JSON_UNESCAPED_UNICODE) |
||
200 | |||
201 | /** |
||
202 | * To string. |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | public function __toString() |
||
210 | |||
211 | /** |
||
212 | * (PHP 5 >= 5.4.0)<br/> |
||
213 | * Specify data which should be serialized to JSON. |
||
214 | * |
||
215 | * @see http://php.net/manual/en/jsonserializable.jsonserialize.php |
||
216 | * |
||
217 | * @return mixed data which can be serialized by <b>json_encode</b>, |
||
218 | * which is a value of any type other than a resource |
||
219 | */ |
||
220 | public function jsonSerialize() |
||
224 | |||
225 | /** |
||
226 | * (PHP 5 >= 5.1.0)<br/> |
||
227 | * String representation of object. |
||
228 | * |
||
229 | * @see http://php.net/manual/en/serializable.serialize.php |
||
230 | * |
||
231 | * @return string the string representation of the object or null |
||
232 | */ |
||
233 | public function serialize() |
||
237 | |||
238 | /** |
||
239 | * (PHP 5 >= 5.0.0)<br/> |
||
240 | * Retrieve an external iterator. |
||
241 | * |
||
242 | * @see http://php.net/manual/en/iteratoraggregate.getiterator.php |
||
243 | * |
||
244 | * @return Traversable An instance of an object implementing <b>Iterator</b> or |
||
245 | * <b>Traversable</b> |
||
246 | */ |
||
247 | public function getIterator() |
||
251 | |||
252 | /** |
||
253 | * (PHP 5 >= 5.1.0)<br/> |
||
254 | * Count elements of an object. |
||
255 | * |
||
256 | * @see http://php.net/manual/en/countable.count.php |
||
257 | * |
||
258 | * @return int The custom count as an integer. |
||
259 | * </p> |
||
260 | * <p> |
||
261 | * The return value is cast to an integer |
||
262 | */ |
||
263 | public function count() |
||
267 | |||
268 | /** |
||
269 | * (PHP 5 >= 5.1.0)<br/> |
||
270 | * Constructs the object. |
||
271 | * |
||
272 | * @see http://php.net/manual/en/serializable.unserialize.php |
||
273 | * |
||
274 | * @param string $serialized <p> |
||
275 | * The string representation of the object. |
||
276 | * </p> |
||
277 | * |
||
278 | * @return mixed|void |
||
279 | */ |
||
280 | public function unserialize($serialized) |
||
284 | |||
285 | /** |
||
286 | * Get a data by key. |
||
287 | * |
||
288 | * @param string $key |
||
289 | * |
||
290 | * @return mixed |
||
291 | */ |
||
292 | public function __get($key) |
||
296 | |||
297 | /** |
||
298 | * Assigns a value to the specified data. |
||
299 | * |
||
300 | * @param string $key |
||
301 | * @param mixed $value |
||
302 | */ |
||
303 | public function __set($key, $value) |
||
307 | |||
308 | /** |
||
309 | * Whether or not an data exists by key. |
||
310 | * |
||
311 | * @param string $key |
||
312 | * |
||
313 | * @return bool |
||
314 | */ |
||
315 | public function __isset($key) |
||
319 | |||
320 | /** |
||
321 | * Unsets an data by key. |
||
322 | * |
||
323 | * @param string $key |
||
324 | */ |
||
325 | public function __unset($key) |
||
329 | |||
330 | /** |
||
331 | * var_export. |
||
332 | * |
||
333 | * @return array |
||
334 | */ |
||
335 | public function __set_state() |
||
339 | |||
340 | /** |
||
341 | * (PHP 5 >= 5.0.0)<br/> |
||
342 | * Whether a offset exists. |
||
343 | * |
||
344 | * @see http://php.net/manual/en/arrayaccess.offsetexists.php |
||
345 | * |
||
346 | * @param mixed $offset <p> |
||
347 | * An offset to check for. |
||
348 | * </p> |
||
349 | * |
||
350 | * @return bool true on success or false on failure. |
||
351 | * The return value will be casted to boolean if non-boolean was returned |
||
352 | */ |
||
353 | public function offsetExists($offset) |
||
357 | |||
358 | /** |
||
359 | * (PHP 5 >= 5.0.0)<br/> |
||
360 | * Offset to unset. |
||
361 | * |
||
362 | * @see http://php.net/manual/en/arrayaccess.offsetunset.php |
||
363 | * |
||
364 | * @param mixed $offset <p> |
||
365 | * The offset to unset. |
||
366 | * </p> |
||
367 | */ |
||
368 | public function offsetUnset($offset) |
||
374 | |||
375 | /** |
||
376 | * (PHP 5 >= 5.0.0)<br/> |
||
377 | * Offset to retrieve. |
||
378 | * |
||
379 | * @see http://php.net/manual/en/arrayaccess.offsetget.php |
||
380 | * |
||
381 | * @param mixed $offset <p> |
||
382 | * The offset to retrieve. |
||
383 | * </p> |
||
384 | * |
||
385 | * @return mixed Can return all value types |
||
386 | */ |
||
387 | public function offsetGet($offset) |
||
391 | |||
392 | /** |
||
393 | * (PHP 5 >= 5.0.0)<br/> |
||
394 | * Offset to set. |
||
395 | * |
||
396 | * @see http://php.net/manual/en/arrayaccess.offsetset.php |
||
397 | * |
||
398 | * @param mixed $offset <p> |
||
399 | * The offset to assign the value to. |
||
400 | * </p> |
||
401 | * @param mixed $value <p> |
||
402 | * The value to set. |
||
403 | * </p> |
||
404 | */ |
||
405 | public function offsetSet($offset, $value) |
||
409 | } |
||
410 |