SortedMiddleware
class SortedMiddleware extends Collection (View source)
Traits
Properties
static protected array | $macros | The registered string macros. | from Macroable |
protected array | $items | The items contained in the collection. | from Collection |
static protected array | $proxies | The methods that can be proxied. | from Collection |
Methods
Dynamically handle calls to the class.
Dynamically handle calls to the class.
Create a new Sorted Middleware container.
Create a new collection instance if the value isn't one already.
Wrap the given value in a collection if applicable.
Create a new collection by invoking the callback a given amount of times.
Get the average value of a given key.
Determine if an item exists in the collection.
Determine if an item exists in the collection using strict comparison.
Cross join with the given lists, returning all possible permutations.
Get the items in the collection that are not present in the given items.
Get the items in the collection that are not present in the given items.
Get the items in the collection whose keys and values are not present in the given items.
Get the items in the collection whose keys and values are not present in the given items.
Get the items in the collection whose keys are not present in the given items.
Get the items in the collection whose keys are not present in the given items.
Execute a callback over each nested chunk of items.
Determine if all items in the collection pass the given test.
Apply the callback if the value is truthy.
Apply the callback if the value is falsy.
Filter items by the given key value pair.
Get an operator checker callback.
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair.
Filter items by the given key value pair using strict comparison.
Filter items by the given key value pair.
Filter items by the given key value pair using strict comparison.
Filter the items, removing any items that don't match the given type.
Get the first item from the collection.
Get the first item by the given key value pair.
Get a flattened array of the items in the collection.
Get an item from the collection by key.
Group an associative array by a field or using a callback.
Key an associative array by a field or using a callback.
Concatenate values of a given key as a string.
Intersect the collection with the given items by key.
Determine if the given value is callable, but not a string.
Get the last item from the collection.
Get the values of a given key.
Run an associative map over each of the items.
Map a collection and flatten the result by a single level.
Create a collection by using this collection for keys and another for its values.
Create a new collection consisting of every n-th element.
"Paginate" the collection by slicing it into a smaller collection.
Partition the collection into two arrays using the given callback or key.
Pass the collection to the given callback and return the result.
Push an item onto the beginning of the collection.
Get and remove an item from the collection.
Get one or a specified number of items randomly from the collection.
Reduce the collection to a single value.
Create a collection of all elements that do not pass a given truth test.
Search the collection for a given value and return the corresponding key if successful.
Slice the underlying collection array.
Split a collection into a certain number of groups.
Sort the collection using the given callback.
Sort the collection in descending order using the given callback.
Sort the collection keys.
Sort the collection keys in descending order.
Splice a portion of the underlying collection array.
Pass the collection to the given callback and then return it.
Transform each item in the collection using a callback.
Return only unique items from the collection array.
Return only unique items from the collection array using strict comparison.
Pad collection to the specified length with a value.
Get a CachingIterator instance.
Results array of items from Collection or Arrayable.
Sort the middlewares by the given priority map.
Splice a middleware into a new position and remove the old entry.
Details
static void
macro(string $name, object|callable $macro)
Register a custom macro.
static mixed
__callStatic(string $method, array $parameters)
Dynamically handle calls to the class.
mixed
__call(string $method, array $parameters)
Dynamically handle calls to the class.
at line 16
void
__construct(array $priorityMap, array|Collection $middlewares)
Create a new Sorted Middleware container.
in Collection at line 81
static Collection
make(mixed $items = [])
Create a new collection instance if the value isn't one already.
in Collection at line 92
static Collection
wrap(mixed $value)
Wrap the given value in a collection if applicable.
in Collection at line 105
static array
unwrap(array|Collection $value)
Get the underlying items from the given collection if applicable.
in Collection at line 117
static Collection
times(int $number, callable $callback = null)
Create a new collection by invoking the callback a given amount of times.
in Collection at line 135
array
all()
Get all of the items in the collection.
in Collection at line 146
mixed
avg(callable|string|null $callback = null)
Get the average value of a given key.
in Collection at line 159
mixed
average(callable|string|null $callback = null)
Alias for the "avg" method.
in Collection at line 170
mixed
median(null $key = null)
Get the median of a given key.
in Collection at line 198
array|null
mode(mixed $key = null)
Get the mode of a given key.
in Collection at line 228
Collection
collapse()
Collapse the collection of items into a single array.
in Collection at line 241
bool
contains(mixed $key, mixed $operator = null, mixed $value = null)
Determine if an item exists in the collection.
in Collection at line 263
bool
containsStrict(mixed $key, mixed $value = null)
Determine if an item exists in the collection using strict comparison.
in Collection at line 284
Collection
crossJoin(mixed ...$lists)
Cross join with the given lists, returning all possible permutations.
in Collection at line 296
void
dd(...$args)
Dump the collection and end the script.
in Collection at line 308
$this
dump()
Dump the collection.
in Collection at line 325
Collection
diff(mixed $items)
Get the items in the collection that are not present in the given items.
in Collection at line 337
Collection
diffUsing(mixed $items, callable $callback)
Get the items in the collection that are not present in the given items.
in Collection at line 348
Collection
diffAssoc(mixed $items)
Get the items in the collection whose keys and values are not present in the given items.
in Collection at line 360
Collection
diffAssocUsing(mixed $items, callable $callback)
Get the items in the collection whose keys and values are not present in the given items.
in Collection at line 371
Collection
diffKeys(mixed $items)
Get the items in the collection whose keys are not present in the given items.
in Collection at line 383
Collection
diffKeysUsing(mixed $items, callable $callback)
Get the items in the collection whose keys are not present in the given items.
in Collection at line 394
$this
each(callable $callback)
Execute a callback over each item.
in Collection at line 411
Collection
eachSpread(callable $callback)
Execute a callback over each nested chunk of items.
in Collection at line 428
bool
every(string|callable $key, mixed $operator = null, mixed $value = null)
Determine if all items in the collection pass the given test.
in Collection at line 451
Collection
except(Collection|mixed $keys)
Get all items except for those with the specified keys.
in Collection at line 468
Collection
filter(callable $callback = null)
Run a filter over each of the items.
in Collection at line 485
Collection|mixed
when(bool $value, callable $callback, callable $default = null)
Apply the callback if the value is truthy.
in Collection at line 504
Collection|mixed
unless(bool $value, callable $callback, callable $default = null)
Apply the callback if the value is falsy.
in Collection at line 517
Collection
where(string $key, mixed $operator, mixed $value = null)
Filter items by the given key value pair.
in Collection at line 530
protected Closure
operatorForWhere(string $key, string $operator, mixed $value = null)
Get an operator checker callback.
in Collection at line 572
Collection
whereStrict(string $key, mixed $value)
Filter items by the given key value pair using strict comparison.
in Collection at line 585
Collection
whereIn(string $key, mixed $values, bool $strict = false)
Filter items by the given key value pair.
in Collection at line 601
Collection
whereInStrict(string $key, mixed $values)
Filter items by the given key value pair using strict comparison.
in Collection at line 614
Collection
whereNotIn(string $key, mixed $values, bool $strict = false)
Filter items by the given key value pair.
in Collection at line 630
Collection
whereNotInStrict(string $key, mixed $values)
Filter items by the given key value pair using strict comparison.
in Collection at line 641
Collection
whereInstanceOf(string $type)
Filter the items, removing any items that don't match the given type.
in Collection at line 655
mixed
first(callable $callback = null, mixed $default = null)
Get the first item from the collection.
in Collection at line 668
Collection
firstWhere(string $key, mixed $operator, mixed $value = null)
Get the first item by the given key value pair.
in Collection at line 679
Collection
flatten(int $depth = INF)
Get a flattened array of the items in the collection.
in Collection at line 689
Collection
flip()
Flip the items in the collection.
in Collection at line 700
$this
forget(string|array $keys)
Remove an item from the collection by key.
in Collection at line 716
mixed
get(mixed $key, mixed $default = null)
Get an item from the collection by key.
in Collection at line 732
Collection
groupBy(callable|string $groupBy, bool $preserveKeys = false)
Group an associative array by a field or using a callback.
in Collection at line 777
Collection
keyBy(callable|string $keyBy)
Key an associative array by a field or using a callback.
in Collection at line 802
bool
has(mixed $key)
Determine if an item exists in the collection by key.
in Collection at line 822
string
implode(string $value, string $glue = null)
Concatenate values of a given key as a string.
in Collection at line 839
Collection
intersect(mixed $items)
Intersect the collection with the given items.
in Collection at line 850
Collection
intersectByKeys(mixed $items)
Intersect the collection with the given items by key.
in Collection at line 862
bool
isEmpty()
Determine if the collection is empty or not.
in Collection at line 872
bool
isNotEmpty()
Determine if the collection is not empty.
in Collection at line 883
protected bool
useAsCallable(mixed $value)
Determine if the given value is callable, but not a string.
in Collection at line 893
Collection
keys()
Get the keys of the collection items.
in Collection at line 905
mixed
last(callable $callback = null, mixed $default = null)
Get the last item from the collection.
in Collection at line 917
Collection
pluck(string|array $value, string|null $key = null)
Get the values of a given key.
in Collection at line 928
Collection
map(callable $callback)
Run a map over each of the items.
in Collection at line 943
Collection
mapSpread(callable $callback)
Run a map over each nested chunk of items.
in Collection at line 960
Collection
mapToDictionary(callable $callback)
Run a dictionary map over the items.
The callback should return an associative array with a single key/value pair.
in Collection at line 989
Collection
mapToGroups(callable $callback)
Run a grouping map over the items.
The callback should return an associative array with a single key/value pair.
in Collection at line 1004
Collection
mapWithKeys(callable $callback)
Run an associative map over each of the items.
The callback should return an associative array with a single key/value pair.
in Collection at line 1025
Collection
flatMap(callable $callback)
Map a collection and flatten the result by a single level.
in Collection at line 1036
Collection
mapInto(string $class)
Map the values into a new class.
in Collection at line 1049
mixed
max(callable|string|null $callback = null)
Get the max value of a given key.
in Collection at line 1068
Collection
merge(mixed $items)
Merge the collection with the given items.
in Collection at line 1079
Collection
combine(mixed $values)
Create a collection by using this collection for keys and another for its values.
in Collection at line 1090
Collection
union(mixed $items)
Union the collection with the given items.
in Collection at line 1101
mixed
min(callable|string|null $callback = null)
Get the min value of a given key.
in Collection at line 1121
Collection
nth(int $step, int $offset = 0)
Create a new collection consisting of every n-th element.
in Collection at line 1144
Collection
only(mixed $keys)
Get the items with the specified keys.
in Collection at line 1166
Collection
forPage(int $page, int $perPage)
"Paginate" the collection by slicing it into a smaller collection.
in Collection at line 1181
Collection
partition(callable|string $key, mixed $operator = null, mixed $value = null)
Partition the collection into two arrays using the given callback or key.
in Collection at line 1202
mixed
pipe(callable $callback)
Pass the collection to the given callback and return the result.
in Collection at line 1212
mixed
pop()
Get and remove the last item from the collection.
in Collection at line 1224
$this
prepend(mixed $value, mixed $key = null)
Push an item onto the beginning of the collection.
in Collection at line 1237
$this
push(mixed $value)
Push an item onto the end of the collection.
in Collection at line 1250
Collection
concat(Traversable|array $source)
Push all of the given items onto the collection.
in Collection at line 1268
mixed
pull(mixed $key, mixed $default = null)
Get and remove an item from the collection.
in Collection at line 1280
$this
put(mixed $key, mixed $value)
Put an item in the collection by key.
in Collection at line 1295
Collection|mixed
random(int|null $number = null)
Get one or a specified number of items randomly from the collection.
in Collection at line 1311
mixed
reduce(callable $callback, mixed $initial = null)
Reduce the collection to a single value.
in Collection at line 1322
Collection
reject(callable|mixed $callback)
Create a collection of all elements that do not pass a given truth test.
in Collection at line 1340
Collection
reverse()
Reverse items order.
in Collection at line 1352
mixed
search(mixed $value, bool $strict = false)
Search the collection for a given value and return the corresponding key if successful.
in Collection at line 1372
mixed
shift()
Get and remove the first item from the collection.
in Collection at line 1383
Collection
shuffle(int $seed = null)
Shuffle the items in the collection.
in Collection at line 1395
Collection
slice(int $offset, int $length = null)
Slice the underlying collection array.
in Collection at line 1406
Collection
split(int $numberOfGroups)
Split a collection into a certain number of groups.
in Collection at line 1423
Collection
chunk(int $size)
Chunk the underlying collection array.
in Collection at line 1444
Collection
sort(callable $callback = null)
Sort through each item with a callback.
in Collection at line 1463
Collection
sortBy(callable|string $callback, int $options = SORT_REGULAR, bool $descending = false)
Sort the collection using the given callback.
in Collection at line 1496
Collection
sortByDesc(callable|string $callback, int $options = SORT_REGULAR)
Sort the collection in descending order using the given callback.
in Collection at line 1508
Collection
sortKeys(int $options = SORT_REGULAR, bool $descending = false)
Sort the collection keys.
in Collection at line 1523
Collection
sortKeysDesc(int $options = SORT_REGULAR)
Sort the collection keys in descending order.
in Collection at line 1536
Collection
splice(int $offset, int|null $length = null, mixed $replacement = [])
Splice a portion of the underlying collection array.
in Collection at line 1551
mixed
sum(callable|string|null $callback = null)
Get the sum of the given values.
in Collection at line 1570
Collection
take(int $limit)
Take the first or last {$limit} items.
in Collection at line 1585
$this
tap(callable $callback)
Pass the collection to the given callback and then return it.
in Collection at line 1598
$this
transform(callable $callback)
Transform each item in the collection using a callback.
in Collection at line 1612
Collection
unique(string|callable|null $key = null, bool $strict = false)
Return only unique items from the collection array.
in Collection at line 1633
Collection
uniqueStrict(string|callable|null $key = null)
Return only unique items from the collection array using strict comparison.
in Collection at line 1643
Collection
values()
Reset the keys on the underlying array.
in Collection at line 1654
protected callable
valueRetriever(string $value)
Get a value retrieving callback.
in Collection at line 1674
Collection
zip(mixed $items)
Zip the collection together with one or more arrays.
e.g. new Collection([1, 2, 3])->zip([4, 5, 6]); => [[1, 4], [2, 5], [3, 6]]
in Collection at line 1694
Collection
pad(int $size, mixed $value)
Pad collection to the specified length with a value.
in Collection at line 1704
array
toArray()
Get the collection of items as a plain array.
in Collection at line 1716
array
jsonSerialize()
Convert the object into something JSON serializable.
in Collection at line 1737
string
toJson(int $options = 0)
Get the collection of items as JSON.
in Collection at line 1747
ArrayIterator
getIterator()
Get an iterator for the items.
in Collection at line 1758
CachingIterator
getCachingIterator(int $flags = CachingIterator::CALL_TOSTRING)
Get a CachingIterator instance.
in Collection at line 1768
int
count()
Count the number of items in the collection.
in Collection at line 1778
Collection
toBase()
Get a base Support collection instance from this collection.
in Collection at line 1789
bool
offsetExists(mixed $key)
Determine if an item exists at an offset.
in Collection at line 1800
mixed
offsetGet(mixed $key)
Get an item at a given offset.
in Collection at line 1812
void
offsetSet(mixed $key, mixed $value)
Set the item at a given offset.
in Collection at line 1827
void
offsetUnset(string $key)
Unset the item at a given offset.
in Collection at line 1837
string
__toString()
Convert the collection to its string representation.
in Collection at line 1848
protected array
getArrayableItems(mixed $items)
Results array of items from Collection or Arrayable.
in Collection at line 1873
static void
proxy(string $method)
Add a method to the list of proxied methods.
in Collection at line 1886
mixed
__get(string $key)
Dynamically access collection proxies.
at line 34
protected array
sortMiddleware(array $priorityMap, array $middlewares)
Sort the middlewares by the given priority map.
Each call to this method makes one discrete middleware movement if necessary.
at line 76
protected array
moveMiddleware(array $middlewares, int $from, int $to)
Splice a middleware into a new position and remove the old entry.