-
Notifications
You must be signed in to change notification settings - Fork 16
/
Collection.php
733 lines (632 loc) · 13.1 KB
/
Collection.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
<?php
namespace Illuminate\Support;
use ArrayAccess;
use ArrayIterator;
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
use Illuminate\Support\Traits\EnumeratesValues;
use Illuminate\Support\Traits\Macroable;
use Traversable;
use stdClass;
abstract class Collection
{
/**
* Get all of the items in the collection.
*/
abstract public function all(
):array;
/**
* Get the average value of a given key.
*/
abstract public function avg(
$callback = null
);
/**
* Get the mode of a given key.
*/
abstract public function mode(
$key = null
):array;
/**
* Collapse the collection of items into a single array.
*/
abstract public function collapse(
):Collection;
/**
* Determine if an item exists in the collection.
*/
abstract public function contains(
$key,
$operator = null,
$value = null
):bool;
/**
* Determine if an item exists, using strict comparison.
*/
abstract public function containsStrict(
$key,
$value = null
):bool;
/**
* Cross join with the given lists, returning all possible permutations.
*/
abstract public function crossJoin(
$lists
):Collection;
/**
* Get the items in the collection that are not present in the given items.
*/
abstract public function diff(
$items
):Collection;
/**
* Get the items in the collection whose keys and values are not present in the given items.
*/
abstract public function diffAssoc(
$items
):Collection;
/**
* Get the items in the collection whose keys are not present in the given items.
*/
abstract public function diffKeys(
$items
):Collection;
/**
* Get all items except for those with the specified keys.
*/
abstract public function except(
$keys
):Collection;
/**
* Run a filter over each of the items.
*/
abstract public function filter(
callable $callback = null
):Collection;
/**
* Get the first item from the collection passing the given truth test.
*/
abstract public function first(
callable $callback = null,
$default = null
);
/**
* Flip the items in the collection.
*/
abstract public function flip(
):Collection;
/**
* Remove an item from the collection by key.
*/
abstract public function forget(
$keys
):Collection;
/**
* Get an item from the collection by key.
*/
abstract public function get(
$key,
$default = null
);
/**
* Group an associative array by a field or using a callback.
*/
abstract public function groupBy(
$groupBy,
bool $preserveKeys = false
):Collection;
/**
* Key an associative array by a field or using a callback.
*/
abstract public function keyBy(
$keyBy
):Collection;
/**
* Determine if an item exists in the collection by key.
*/
abstract public function has(
$key
):bool;
/**
* Concatenate values of a given key as a string.
*/
abstract public function implode(
$value,
string $glue = null
):string;
/**
* Intersect the collection with the given items.
*/
abstract public function intersect(
$items
):Collection;
/**
* Intersect the collection with the given items by key.
*/
abstract public function intersectByKeys(
$items
):Collection;
/**
* Determine if the collection is empty or not.
*/
abstract public function isEmpty(
):bool;
/**
* Get the keys of the collection items.
*/
abstract public function keys(
):Collection;
/**
* Get the last item from the collection.
*/
abstract public function last(
callable $callback = null,
$default = null
);
/**
* Get the values of a given key.
*/
abstract public function pluck(
$value,
string $key = null
):Collection;
/**
* Run a map over each of the items.
*/
abstract public function map(
callable $callback
):Collection;
/**
* Run a dictionary map over the items.
*/
abstract public function mapToDictionary(
callable $callback
):Collection;
/**
* Run an associative map over each of the items.
*/
abstract public function mapWithKeys(
callable $callback
):Collection;
/**
* Merge the collection with the given items.
*/
abstract public function merge(
$items
):Collection;
/**
* Create a collection by using this collection for keys and another for its values.
*/
abstract public function combine(
$values
):Collection;
/**
* Union the collection with the given items.
*/
abstract public function union(
$items
):Collection;
/**
* Create a new collection consisting of every n-th element.
*/
abstract public function nth(
int $step,
int $offset = 0
):Collection;
/**
* Get the items with the specified keys.
*/
abstract public function only(
$keys
):Collection;
/**
* Get and remove the last N items from the collection.
*/
abstract public function pop(
int $count = 1
):Collection;
/**
* Push an item onto the beginning of the collection.
*/
abstract public function prepend(
$value,
$key = null
):Collection;
/**
* Push one or more items onto the end of the collection.
*/
abstract public function push(
$values
):Collection;
/**
* Get and remove an item from the collection.
*/
abstract public function pull(
$key,
$default = null
);
/**
* Put an item in the collection by key.
*/
abstract public function put(
$key,
$value
):Collection;
/**
* Get one or a specified number of items randomly from the collection.
*/
abstract public function random(
$number = null
):Collection;
/**
* Reverse items order.
*/
abstract public function reverse(
):Collection;
/**
* Search the collection for a given value and return the corresponding key if successful.
*/
abstract public function search(
$value,
bool $strict = false
);
/**
* Get and remove the first N items from the collection.
*/
abstract public function shift(
int $count = 1
):Collection;
/**
* Shuffle the items in the collection.
*/
abstract public function shuffle(
int $seed = null
):Collection;
/**
* Slice the underlying collection array.
*/
abstract public function slice(
int $offset,
int $length = null
):Collection;
/**
* Split a collection into a certain number of groups.
*/
abstract public function split(
int $numberOfGroups
):Collection;
/**
* Chunk the collection into chunks of the given size.
*/
abstract public function chunk(
int $size
):Collection;
/**
* Sort through each item with a callback.
*/
abstract public function sort(
$callback = null
):Collection;
/**
* Splice a portion of the underlying collection array.
*/
abstract public function splice(
int $offset,
int $length = null,
array $replacement = []
):Collection;
/**
* Take the first or last {$limit} items.
*/
abstract public function take(
int $limit
):Collection;
/**
* Transform each item in the collection using a callback.
*/
abstract public function transform(
callable $callback
):Collection;
/**
* Return only unique items from the collection array.
*/
abstract public function unique(
$key = null,
bool $strict = false
):Collection;
/**
* Reset the keys on the underlying array.
*/
abstract public function values(
):Collection;
/**
* Zip the collection together with one or more arrays.
*/
abstract public function zip(
$items
):Collection;
/**
* Pad collection to the specified length with a value.
*/
abstract public function pad(
int $size,
$value
):Collection;
/**
* Count the number of items in the collection.
*/
abstract public function count(
):int;
/**
* Determine if an item exists at an offset.
*/
abstract public function offsetExists(
$key
):bool;
/**
* Get an item at a given offset.
*/
abstract public function offsetGet(
$key
);
/**
* Set the item at a given offset.
*/
abstract public function offsetSet(
$key,
$value
);
/**
* Unset the item at a given offset.
*/
abstract public function offsetUnset(
$key
);
/**
* Create a new collection instance if the value isn't one already.
*/
abstract public static function make(
$items = []
):Collection;
/**
* Wrap the given value in a collection if applicable.
*/
abstract public static function wrap(
$value
):Collection;
/**
* Get the underlying items from the given collection if applicable.
*/
abstract public static function unwrap(
$value
):array;
/**
* Create a new collection by invoking the callback a given amount of times.
*/
abstract public static function times(
int $number,
callable $callback = null
):Collection;
/**
* Alias for the "avg" method.
*/
abstract public function average(
$callback = null
);
/**
* Execute a callback over each item.
*/
abstract public function each(
callable $callback
):Collection;
/**
* Execute a callback over each nested chunk of items.
*/
abstract public function eachSpread(
callable $callback
):Collection;
/**
* Determine if all items pass the given truth test.
*/
abstract public function every(
$key,
$operator = null,
$value = null
):bool;
/**
* Get the first item by the given key value pair.
*/
abstract public function firstWhere(
$key,
$operator = null,
$value = null
);
/**
* Determine if the collection is not empty.
*/
abstract public function isNotEmpty(
):bool;
/**
* Run a map over each nested chunk of items.
*/
abstract public function mapSpread(
callable $callback
):Collection;
/**
* Run a grouping map over the items.
*/
abstract public function mapToGroups(
callable $callback
):Collection;
/**
* Map a collection and flatten the result by a single level.
*/
abstract public function flatMap(
callable $callback
):Collection;
/**
* Map the values into a new class.
*/
abstract public function mapInto(
string $class
):Collection;
/**
* Get the min value of a given key.
*/
abstract public function min(
$callback = null
);
/**
* Get the max value of a given key.
*/
abstract public function max(
$callback = null
);
/**
* "Paginate" the collection by slicing it into a smaller collection.
*/
abstract public function forPage(
int $page,
int $perPage
):Collection;
/**
* Partition the collection into two arrays using the given callback or key.
*/
abstract public function partition(
$key,
$operator = null,
$value = null
):Collection;
/**
* Get the sum of the given values.
*/
abstract public function sum(
$callback = null
);
/**
* Filter items by the given key value pair.
*/
abstract public function where(
$key,
$operator = null,
$value = null
):Collection;
/**
* Filter items by the given key value pair using strict comparison.
*/
abstract public function whereStrict(
string $key,
$value
):Collection;
/**
* Filter items by the given key value pair.
*/
abstract public function whereIn(
string $key,
$values,
bool $strict = false
):Collection;
/**
* Filter items by the given key value pair using strict comparison.
*/
abstract public function whereInStrict(
string $key,
$values
):Collection;
/**
* Filter items by the given key value pair.
*/
abstract public function whereNotIn(
string $key,
$values,
bool $strict = false
):Collection;
/**
* Filter items by the given key value pair using strict comparison.
*/
abstract public function whereNotInStrict(
string $key,
$values
):Collection;
/**
* Pass the collection to the given callback and return the result.
*/
abstract public function pipe(
callable $callback
);
/**
* Reduce the collection to a single value.
*/
abstract public function reduce(
callable $callback,
$initial = null
);
/**
* Create a collection of all elements that do not pass a given truth test.
*/
abstract public function reject(
$callback = true
):Collection;
/**
* Pass the collection to the given callback and then return it.
*/
abstract public function tap(
callable $callback
):Collection;
/**
* Return only unique items from the collection array using strict comparison.
*/
abstract public function uniqueStrict(
$key = null
):Collection;
/**
* Get the collection of items as a plain array.
*/
abstract public function toArray(
):array;
/**
* Convert the object into something JSON serializable.
*/
abstract public function jsonSerialize(
):array;
/**
* Get the collection of items as JSON.
*/
abstract public function toJson(
int $options = 0
):string;
/**
* Add a method to the list of proxied methods.
*/
abstract public static function proxy(
string $method
);
/**
* Apply the callback if the given "value" is (or resolves to) truthy.
*/
abstract public function when(
$value = null,
callable $callback = null,
callable $default = null
):Collection;
/**
* Apply the callback if the given "value" is (or resolves to) falsy.
*/
abstract public function unless(
$value = null,
callable $callback = null,
callable $default = null
):Collection;
/**
* Register a custom macro.
*/
abstract public static function macro(
string $name,
$macro
);
/**
* Checks if macro is registered.
*/
abstract public static function hasMacro(
string $name
):bool;
}