mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-10-29 12:43:25 +00:00
[Web] Update composer libraries
This commit is contained in:
1297 files changed
+71585
-24460
No files matched your search
+465
-92
@@ -4,8 +4,15 @@ namespace Illuminate\Support;
|
||||
|
||||
use ArgumentCountError;
|
||||
use ArrayAccess;
|
||||
use Closure;
|
||||
use Illuminate\Contracts\Support\Arrayable;
|
||||
use Illuminate\Contracts\Support\Jsonable;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
use Random\Randomizer;
|
||||
use Traversable;
|
||||
use WeakMap;
|
||||
|
||||
class Arr
|
||||
{
|
||||
@@ -22,6 +29,33 @@ class Arr
|
||||
return is_array($value) || $value instanceof ArrayAccess;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the given value is arrayable.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return ($value is array
|
||||
* ? true
|
||||
* : ($value is \Illuminate\Contracts\Support\Arrayable
|
||||
* ? true
|
||||
* : ($value is \Traversable
|
||||
* ? true
|
||||
* : ($value is \Illuminate\Contracts\Support\Jsonable
|
||||
* ? true
|
||||
* : ($value is \JsonSerializable ? true : false)
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
public static function arrayable($value)
|
||||
{
|
||||
return is_array($value)
|
||||
|| $value instanceof Arrayable
|
||||
|| $value instanceof Traversable
|
||||
|| $value instanceof Jsonable
|
||||
|| $value instanceof JsonSerializable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an element to an array using "dot" notation if it doesn't exist.
|
||||
*
|
||||
@@ -39,6 +73,42 @@ class Arr
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an array item from an array using "dot" notation.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function array(ArrayAccess|array $array, string|int|null $key, ?array $default = null): array
|
||||
{
|
||||
$value = Arr::get($array, $key, $default);
|
||||
|
||||
if (! is_array($value)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Array value for key [%s] must be an array, %s found.', $key, gettype($value))
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a boolean item from an array using "dot" notation.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function boolean(ArrayAccess|array $array, string|int|null $key, ?bool $default = null): bool
|
||||
{
|
||||
$value = Arr::get($array, $key, $default);
|
||||
|
||||
if (! is_bool($value)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Array value for key [%s] must be a boolean, %s found.', $key, gettype($value))
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse an array of arrays into a single array.
|
||||
*
|
||||
@@ -51,12 +121,10 @@ class Arr
|
||||
|
||||
foreach ($array as $values) {
|
||||
if ($values instanceof Collection) {
|
||||
$values = $values->all();
|
||||
} elseif (! is_array($values)) {
|
||||
continue;
|
||||
$results[] = $values->all();
|
||||
} elseif (is_array($values)) {
|
||||
$results[] = $values;
|
||||
}
|
||||
|
||||
$results[] = $values;
|
||||
}
|
||||
|
||||
return array_merge([], ...$results);
|
||||
@@ -65,8 +133,10 @@ class Arr
|
||||
/**
|
||||
* Cross join the given arrays, returning all possible permutations.
|
||||
*
|
||||
* @param iterable ...$arrays
|
||||
* @return array
|
||||
* @template TValue
|
||||
*
|
||||
* @param iterable<TValue> ...$arrays
|
||||
* @return array<int, array<array-key, TValue>>
|
||||
*/
|
||||
public static function crossJoin(...$arrays)
|
||||
{
|
||||
@@ -92,8 +162,11 @@ class Arr
|
||||
/**
|
||||
* Divide an array into two arrays. One with keys and the other with values.
|
||||
*
|
||||
* @param array $array
|
||||
* @return array
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
* @return array{TKey[], TValue[]}
|
||||
*/
|
||||
public static function divide($array)
|
||||
{
|
||||
@@ -105,19 +178,29 @@ class Arr
|
||||
*
|
||||
* @param iterable $array
|
||||
* @param string $prepend
|
||||
* @param int $depth
|
||||
* @return array
|
||||
*/
|
||||
public static function dot($array, $prepend = '')
|
||||
public static function dot($array, $prepend = '', $depth = INF)
|
||||
{
|
||||
$results = [];
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if (is_array($value) && ! empty($value)) {
|
||||
$results = array_merge($results, static::dot($value, $prepend.$key.'.'));
|
||||
} else {
|
||||
$results[$prepend.$key] = $value;
|
||||
$flatten = function ($data, $prefix, $currentDepth) use (&$results, &$flatten, $depth): void {
|
||||
foreach ($data as $key => $value) {
|
||||
$newKey = $prefix.$key;
|
||||
|
||||
if (is_array($value) && ! empty($value) && $currentDepth < $depth) {
|
||||
$flatten($value, $newKey.'.', $currentDepth + 1);
|
||||
} else {
|
||||
$results[$newKey] = $value;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
$flatten($array, $prepend, 0);
|
||||
|
||||
// Destroy self-referencing closure to avoid memory leak...
|
||||
$flatten = null;
|
||||
|
||||
return $results;
|
||||
}
|
||||
@@ -153,11 +236,28 @@ class Arr
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all of the given array except for a specified array of values.
|
||||
*
|
||||
* @param array $array
|
||||
* @param mixed $values
|
||||
* @param bool $strict
|
||||
* @return array
|
||||
*/
|
||||
public static function exceptValues($array, $values, $strict = false)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
return array_filter($array, function ($value) use ($values, $strict) {
|
||||
return ! in_array($value, $values, $strict);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the given key exists in the provided array.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|int $key
|
||||
* @param string|int|float $key
|
||||
* @return bool
|
||||
*/
|
||||
public static function exists($array, $key)
|
||||
@@ -170,7 +270,7 @@ class Arr
|
||||
return $array->offsetExists($key);
|
||||
}
|
||||
|
||||
if (is_float($key)) {
|
||||
if (is_float($key) || is_null($key)) {
|
||||
$key = (string) $key;
|
||||
}
|
||||
|
||||
@@ -178,12 +278,16 @@ class Arr
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first element in an array passing a given truth test.
|
||||
* Return the first element in an iterable passing a given truth test.
|
||||
*
|
||||
* @param iterable $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
* @template TFirstDefault
|
||||
*
|
||||
* @param iterable<TKey, TValue> $array
|
||||
* @param (callable(TValue, TKey): bool)|null $callback
|
||||
* @param TFirstDefault|(\Closure(): TFirstDefault) $default
|
||||
* @return TValue|TFirstDefault
|
||||
*/
|
||||
public static function first($array, ?callable $callback = null, $default = null)
|
||||
{
|
||||
@@ -192,6 +296,10 @@ class Arr
|
||||
return value($default);
|
||||
}
|
||||
|
||||
if (is_array($array)) {
|
||||
return array_first($array);
|
||||
}
|
||||
|
||||
foreach ($array as $item) {
|
||||
return $item;
|
||||
}
|
||||
@@ -199,27 +307,29 @@ class Arr
|
||||
return value($default);
|
||||
}
|
||||
|
||||
foreach ($array as $key => $value) {
|
||||
if ($callback($value, $key)) {
|
||||
return $value;
|
||||
}
|
||||
}
|
||||
$array = static::from($array);
|
||||
|
||||
return value($default);
|
||||
$key = array_find_key($array, $callback);
|
||||
|
||||
return $key !== null ? $array[$key] : value($default);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the last element in an array passing a given truth test.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|null $callback
|
||||
* @param mixed $default
|
||||
* @return mixed
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
* @template TLastDefault
|
||||
*
|
||||
* @param iterable<TKey, TValue> $array
|
||||
* @param (callable(TValue, TKey): bool)|null $callback
|
||||
* @param TLastDefault|(\Closure(): TLastDefault) $default
|
||||
* @return TValue|TLastDefault
|
||||
*/
|
||||
public static function last($array, ?callable $callback = null, $default = null)
|
||||
{
|
||||
if (is_null($callback)) {
|
||||
return empty($array) ? value($default) : end($array);
|
||||
return empty($array) ? value($default) : array_last($array);
|
||||
}
|
||||
|
||||
return static::first(array_reverse($array, true), $callback, $default);
|
||||
@@ -271,6 +381,24 @@ class Arr
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a float item from an array using "dot" notation.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function float(ArrayAccess|array $array, string|int|null $key, ?float $default = null): float
|
||||
{
|
||||
$value = Arr::get($array, $key, $default);
|
||||
|
||||
if (! is_float($value)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Array value for key [%s] must be a float, %s found.', $key, gettype($value))
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove one or many array items from a given array using "dot" notation.
|
||||
*
|
||||
@@ -315,6 +443,32 @@ class Arr
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying array of items from the given argument.
|
||||
*
|
||||
* @template TKey of array-key = array-key
|
||||
* @template TValue = mixed
|
||||
*
|
||||
* @param array<TKey, TValue>|Enumerable<TKey, TValue>|Arrayable<TKey, TValue>|WeakMap<object, TValue>|Traversable<TKey, TValue>|Jsonable|JsonSerializable|object $items
|
||||
* @return ($items is WeakMap ? list<TValue> : array<TKey, TValue>)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function from($items)
|
||||
{
|
||||
return match (true) {
|
||||
is_array($items) => $items,
|
||||
$items instanceof Enumerable => $items->all(),
|
||||
$items instanceof Arrayable => $items->toArray(),
|
||||
$items instanceof WeakMap => iterator_to_array($items, false),
|
||||
$items instanceof Traversable => iterator_to_array($items),
|
||||
$items instanceof Jsonable => json_decode($items->toJson(), true),
|
||||
$items instanceof JsonSerializable => (array) $items->jsonSerialize(),
|
||||
is_object($items) => (array) $items,
|
||||
default => throw new InvalidArgumentException('Items cannot be represented by a scalar value.'),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an item from an array using "dot" notation.
|
||||
*
|
||||
@@ -338,7 +492,7 @@ class Arr
|
||||
}
|
||||
|
||||
if (! str_contains($key, '.')) {
|
||||
return $array[$key] ?? value($default);
|
||||
return value($default);
|
||||
}
|
||||
|
||||
foreach (explode('.', $key) as $segment) {
|
||||
@@ -386,6 +540,30 @@ class Arr
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if all keys exist in an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|array $keys
|
||||
* @return bool
|
||||
*/
|
||||
public static function hasAll($array, $keys)
|
||||
{
|
||||
$keys = (array) $keys;
|
||||
|
||||
if (! $array || $keys === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach ($keys as $key) {
|
||||
if (! static::has($array, $key)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if any of the keys exist in an array using "dot" notation.
|
||||
*
|
||||
@@ -418,13 +596,55 @@ class Arr
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if all items pass the given truth test.
|
||||
*
|
||||
* @param iterable $array
|
||||
* @param (callable(mixed, array-key): bool) $callback
|
||||
* @return bool
|
||||
*/
|
||||
public static function every($array, callable $callback)
|
||||
{
|
||||
return array_all($array, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if some items pass the given truth test.
|
||||
*
|
||||
* @param iterable $array
|
||||
* @param (callable(mixed, array-key): bool) $callback
|
||||
* @return bool
|
||||
*/
|
||||
public static function some($array, callable $callback)
|
||||
{
|
||||
return array_any($array, $callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an integer item from an array using "dot" notation.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function integer(ArrayAccess|array $array, string|int|null $key, ?int $default = null): int
|
||||
{
|
||||
$value = Arr::get($array, $key, $default);
|
||||
|
||||
if (! is_int($value)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Array value for key [%s] must be an integer, %s found.', $key, gettype($value))
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines if an array is associative.
|
||||
*
|
||||
* An array is "associative" if it doesn't have sequential numerical keys beginning with zero.
|
||||
*
|
||||
* @param array $array
|
||||
* @return bool
|
||||
* @return ($array is list ? false : true)
|
||||
*/
|
||||
public static function isAssoc(array $array)
|
||||
{
|
||||
@@ -437,7 +657,7 @@ class Arr
|
||||
* An array is a "list" if all array keys are sequential integers starting from 0 with no gaps in between.
|
||||
*
|
||||
* @param array $array
|
||||
* @return bool
|
||||
* @return ($array is list ? true : false)
|
||||
*/
|
||||
public static function isList($array)
|
||||
{
|
||||
@@ -463,7 +683,7 @@ class Arr
|
||||
}
|
||||
|
||||
if (count($array) === 1) {
|
||||
return end($array);
|
||||
return array_last($array);
|
||||
}
|
||||
|
||||
$finalItem = array_pop($array);
|
||||
@@ -474,13 +694,13 @@ class Arr
|
||||
/**
|
||||
* Key an associative array by a field or using a callback.
|
||||
*
|
||||
* @param array $array
|
||||
* @param iterable $array
|
||||
* @param callable|array|string $keyBy
|
||||
* @return array
|
||||
*/
|
||||
public static function keyBy($array, $keyBy)
|
||||
{
|
||||
return Collection::make($array)->keyBy($keyBy)->all();
|
||||
return (new Collection($array))->keyBy($keyBy)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -507,6 +727,23 @@ class Arr
|
||||
return array_intersect_key($array, array_flip((array) $keys));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a subset of the items from the given array by value.
|
||||
*
|
||||
* @param array $array
|
||||
* @param mixed $values
|
||||
* @param bool $strict
|
||||
* @return array
|
||||
*/
|
||||
public static function onlyValues($array, $values, $strict = false)
|
||||
{
|
||||
$values = (array) $values;
|
||||
|
||||
return array_filter($array, function ($value) use ($values, $strict) {
|
||||
return in_array($value, $values, $strict);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Select an array of values from an array.
|
||||
*
|
||||
@@ -537,8 +774,8 @@ class Arr
|
||||
* Pluck an array of values from an array.
|
||||
*
|
||||
* @param iterable $array
|
||||
* @param string|array|int|null $value
|
||||
* @param string|array|null $key
|
||||
* @param string|array|int|Closure|null $value
|
||||
* @param string|array|Closure|null $key
|
||||
* @return array
|
||||
*/
|
||||
public static function pluck($array, $value, $key = null)
|
||||
@@ -548,7 +785,9 @@ class Arr
|
||||
[$value, $key] = static::explodePluckParameters($value, $key);
|
||||
|
||||
foreach ($array as $item) {
|
||||
$itemValue = data_get($item, $value);
|
||||
$itemValue = $value instanceof Closure
|
||||
? $value($item)
|
||||
: data_get($item, $value);
|
||||
|
||||
// If the key is "null", we will just append the value to the array and keep
|
||||
// looping. Otherwise we will key the array using the value of the key we
|
||||
@@ -556,7 +795,9 @@ class Arr
|
||||
if (is_null($key)) {
|
||||
$results[] = $itemValue;
|
||||
} else {
|
||||
$itemKey = data_get($item, $key);
|
||||
$itemKey = $key instanceof Closure
|
||||
? $key($item)
|
||||
: data_get($item, $key);
|
||||
|
||||
if (is_object($itemKey) && method_exists($itemKey, '__toString')) {
|
||||
$itemKey = (string) $itemKey;
|
||||
@@ -572,15 +813,15 @@ class Arr
|
||||
/**
|
||||
* Explode the "value" and "key" arguments passed to "pluck".
|
||||
*
|
||||
* @param string|array $value
|
||||
* @param string|array|null $key
|
||||
* @param Closure|array|string $value
|
||||
* @param string|array|Closure|null $key
|
||||
* @return array
|
||||
*/
|
||||
protected static function explodePluckParameters($value, $key)
|
||||
{
|
||||
$value = is_string($value) ? explode('.', $value) : $value;
|
||||
|
||||
$key = is_null($key) || is_array($key) ? $key : explode('.', $key);
|
||||
$key = is_null($key) || is_array($key) || $key instanceof Closure ? $key : explode('.', $key);
|
||||
|
||||
return [$value, $key];
|
||||
}
|
||||
@@ -634,6 +875,25 @@ class Arr
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Run a map over each nested chunk of items.
|
||||
*
|
||||
* @template TKey
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, array> $array
|
||||
* @param callable(mixed...): TValue $callback
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function mapSpread(array $array, callable $callback)
|
||||
{
|
||||
return static::map($array, function ($chunk, $key) use ($callback) {
|
||||
$chunk[] = $key;
|
||||
|
||||
return $callback(...$chunk);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an item onto the beginning of an array.
|
||||
*
|
||||
@@ -703,24 +963,24 @@ class Arr
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($array) || (! is_null($number) && $number <= 0)) {
|
||||
return is_null($number) ? null : [];
|
||||
}
|
||||
|
||||
$keys = (new Randomizer)->pickArrayKeys($array, $requested);
|
||||
|
||||
if (is_null($number)) {
|
||||
return $array[array_rand($array)];
|
||||
return $array[$keys[0]];
|
||||
}
|
||||
|
||||
if ((int) $number === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$keys = array_rand($array, $number);
|
||||
|
||||
$results = [];
|
||||
|
||||
if ($preserveKeys) {
|
||||
foreach ((array) $keys as $key) {
|
||||
foreach ($keys as $key) {
|
||||
$results[$key] = $array[$key];
|
||||
}
|
||||
} else {
|
||||
foreach ((array) $keys as $key) {
|
||||
foreach ($keys as $key) {
|
||||
$results[] = $array[$key];
|
||||
}
|
||||
}
|
||||
@@ -768,57 +1028,102 @@ class Arr
|
||||
return $array;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push an item into an array using "dot" notation.
|
||||
*
|
||||
* @param \ArrayAccess|array $array
|
||||
* @param string|int|null $key
|
||||
* @param mixed $values
|
||||
* @return array
|
||||
*/
|
||||
public static function push(ArrayAccess|array &$array, string|int|null $key, mixed ...$values): array
|
||||
{
|
||||
$target = static::array($array, $key, []);
|
||||
|
||||
array_push($target, ...$values);
|
||||
|
||||
return static::set($array, $key, $target);
|
||||
}
|
||||
|
||||
/**
|
||||
* Shuffle the given array and return the result.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int|null $seed
|
||||
* @return array
|
||||
*/
|
||||
public static function shuffle($array, $seed = null)
|
||||
public static function shuffle($array)
|
||||
{
|
||||
if (is_null($seed)) {
|
||||
shuffle($array);
|
||||
} else {
|
||||
mt_srand($seed);
|
||||
shuffle($array);
|
||||
mt_srand();
|
||||
return (new Randomizer)->shuffleArray($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first item in the array, but only if exactly one item exists. Otherwise, throw an exception.
|
||||
*
|
||||
* @param array $array
|
||||
* @param (callable(mixed, array-key): array)|null $callback
|
||||
*
|
||||
* @throws \Illuminate\Support\ItemNotFoundException
|
||||
* @throws \Illuminate\Support\MultipleItemsFoundException
|
||||
*/
|
||||
public static function sole($array, ?callable $callback = null)
|
||||
{
|
||||
if ($callback) {
|
||||
$array = static::where($array, $callback);
|
||||
}
|
||||
|
||||
return $array;
|
||||
$count = count($array);
|
||||
|
||||
if ($count === 0) {
|
||||
throw new ItemNotFoundException;
|
||||
}
|
||||
|
||||
if ($count > 1) {
|
||||
throw new MultipleItemsFoundException($count);
|
||||
}
|
||||
|
||||
return static::first($array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the array using the given callback or "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|array|string|null $callback
|
||||
* @return array
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param iterable<TKey, TValue> $array
|
||||
* @param callable|string|null|array<int, (callable(TValue, TValue): -1|0|1)|array{string, 'asc'|'desc'}> $callback
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function sort($array, $callback = null)
|
||||
{
|
||||
return Collection::make($array)->sortBy($callback)->all();
|
||||
return (new Collection($array))->sortBy($callback)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sort the array in descending order using the given callback or "dot" notation.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable|array|string|null $callback
|
||||
* @return array
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param iterable<TKey, TValue> $array
|
||||
* @param callable|string|null|array<int, (callable(TValue, TValue): -1|0|1)|array{string, 'asc'|'desc'}> $callback
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function sortDesc($array, $callback = null)
|
||||
{
|
||||
return Collection::make($array)->sortByDesc($callback)->all();
|
||||
return (new Collection($array))->sortByDesc($callback)->all();
|
||||
}
|
||||
|
||||
/**
|
||||
* Recursively sort an array by keys and values.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $options
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
* @param int-mask-of<SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options
|
||||
* @param bool $descending
|
||||
* @return array
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function sortRecursive($array, $options = SORT_REGULAR, $descending = false)
|
||||
{
|
||||
@@ -830,12 +1135,12 @@ class Arr
|
||||
|
||||
if (! array_is_list($array)) {
|
||||
$descending
|
||||
? krsort($array, $options)
|
||||
: ksort($array, $options);
|
||||
? krsort($array, $options)
|
||||
: ksort($array, $options);
|
||||
} else {
|
||||
$descending
|
||||
? rsort($array, $options)
|
||||
: sort($array, $options);
|
||||
? rsort($array, $options)
|
||||
: sort($array, $options);
|
||||
}
|
||||
|
||||
return $array;
|
||||
@@ -844,20 +1149,41 @@ class Arr
|
||||
/**
|
||||
* Recursively sort an array by keys and values in descending order.
|
||||
*
|
||||
* @param array $array
|
||||
* @param int $options
|
||||
* @return array
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
* @param int-mask-of<SORT_REGULAR|SORT_NUMERIC|SORT_STRING|SORT_LOCALE_STRING|SORT_NATURAL|SORT_FLAG_CASE> $options
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function sortRecursiveDesc($array, $options = SORT_REGULAR)
|
||||
{
|
||||
return static::sortRecursive($array, $options, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a string item from an array using "dot" notation.
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public static function string(ArrayAccess|array $array, string|int|null $key, ?string $default = null): string
|
||||
{
|
||||
$value = Arr::get($array, $key, $default);
|
||||
|
||||
if (! is_string($value)) {
|
||||
throw new InvalidArgumentException(
|
||||
sprintf('Array value for key [%s] must be a string, %s found.', $key, gettype($value))
|
||||
);
|
||||
}
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Conditionally compile classes from an array into a CSS class list.
|
||||
*
|
||||
* @param array $array
|
||||
* @return string
|
||||
* @param array<string, bool>|array<int, string|int>|string $array
|
||||
* @return ($array is array<string, false> ? '' : ($array is '' ? '' : ($array is array{} ? '' : non-empty-string)))
|
||||
*/
|
||||
public static function toCssClasses($array)
|
||||
{
|
||||
@@ -879,8 +1205,8 @@ class Arr
|
||||
/**
|
||||
* Conditionally compile styles from an array into a style list.
|
||||
*
|
||||
* @param array $array
|
||||
* @return string
|
||||
* @param array<string, bool>|array<int, string|int>|string $array
|
||||
* @return ($array is array<string, false> ? '' : ($array is '' ? '' : ($array is array{} ? '' : non-empty-string)))
|
||||
*/
|
||||
public static function toCssStyles($array)
|
||||
{
|
||||
@@ -902,15 +1228,59 @@ class Arr
|
||||
/**
|
||||
* Filter the array using the given callback.
|
||||
*
|
||||
* @param array $array
|
||||
* @param callable $callback
|
||||
* @return array
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
* @param callable(TValue, TKey): bool $callback
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function where($array, callable $callback)
|
||||
{
|
||||
return array_filter($array, $callback, ARRAY_FILTER_USE_BOTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the array using the negation of the given callback.
|
||||
*
|
||||
* @template TKey of array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue> $array
|
||||
* @param callable(TValue, TKey): bool $callback
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public static function reject($array, callable $callback)
|
||||
{
|
||||
return static::where($array, fn ($value, $key) => ! $callback($value, $key));
|
||||
}
|
||||
|
||||
/**
|
||||
* Partition the array into two arrays using the given callback.
|
||||
*
|
||||
* @template TKey of array-key
|
||||
* @template TValue of mixed
|
||||
*
|
||||
* @param iterable<TKey, TValue> $array
|
||||
* @param callable(TValue, TKey): bool $callback
|
||||
* @return array<int<0, 1>, array<TKey, TValue>>
|
||||
*/
|
||||
public static function partition($array, callable $callback)
|
||||
{
|
||||
$passed = [];
|
||||
$failed = [];
|
||||
|
||||
foreach ($array as $key => $item) {
|
||||
if ($callback($item, $key)) {
|
||||
$passed[$key] = $item;
|
||||
} else {
|
||||
$failed[$key] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
return [$passed, $failed];
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter items where the value is not null.
|
||||
*
|
||||
@@ -925,8 +1295,11 @@ class Arr
|
||||
/**
|
||||
* If the given value is not an array and not null, wrap it in one.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @return array
|
||||
* @template TKey of array-key = array-key
|
||||
* @template TValue
|
||||
*
|
||||
* @param array<TKey, TValue>|TValue|null $value
|
||||
* @return ($value is null ? array{} : ($value is array ? array<TKey, TValue> : array{TValue}))
|
||||
*/
|
||||
public static function wrap($value)
|
||||
{
|
||||
|
||||
+283
-103
@@ -7,6 +7,7 @@ use ArrayIterator;
|
||||
use Illuminate\Contracts\Support\CanBeEscapedWhenCastToString;
|
||||
use Illuminate\Support\Traits\EnumeratesValues;
|
||||
use Illuminate\Support\Traits\Macroable;
|
||||
use Illuminate\Support\Traits\TransformsToResourceCollection;
|
||||
use InvalidArgumentException;
|
||||
use stdClass;
|
||||
use Traversable;
|
||||
@@ -24,7 +25,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* @use \Illuminate\Support\Traits\EnumeratesValues<TKey, TValue>
|
||||
*/
|
||||
use EnumeratesValues, Macroable;
|
||||
use EnumeratesValues, Macroable, TransformsToResourceCollection;
|
||||
|
||||
/**
|
||||
* The items contained in the collection.
|
||||
@@ -37,7 +38,6 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
* Create a new collection.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|null $items
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($items = [])
|
||||
{
|
||||
@@ -49,11 +49,12 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @param int $step
|
||||
* @return static<int, int>
|
||||
*/
|
||||
public static function range($from, $to)
|
||||
public static function range($from, $to, $step = 1)
|
||||
{
|
||||
return new static(range($from, $to));
|
||||
return new static(range($from, $to, $step));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,25 +77,6 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return new LazyCollection($this->items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average value of a given key.
|
||||
*
|
||||
* @param (callable(TValue): float|int)|string|null $callback
|
||||
* @return float|int|null
|
||||
*/
|
||||
public function avg($callback = null)
|
||||
{
|
||||
$callback = $this->valueRetriever($callback);
|
||||
|
||||
$items = $this
|
||||
->map(fn ($value) => $callback($value))
|
||||
->filter(fn ($value) => ! is_null($value));
|
||||
|
||||
if ($count = $items->count()) {
|
||||
return $items->sum() / $count;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the median of a given key.
|
||||
*
|
||||
@@ -104,7 +86,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
public function median($key = null)
|
||||
{
|
||||
$values = (isset($key) ? $this->pluck($key) : $this)
|
||||
->filter(fn ($item) => ! is_null($item))
|
||||
->reject(fn ($item) => is_null($item))
|
||||
->sort()->values();
|
||||
|
||||
$count = $values->count();
|
||||
@@ -113,7 +95,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return;
|
||||
}
|
||||
|
||||
$middle = (int) ($count / 2);
|
||||
$middle = intdiv($count, 2);
|
||||
|
||||
if ($count % 2) {
|
||||
return $values->get($middle);
|
||||
@@ -160,6 +142,36 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return new static(Arr::collapse($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapse the collection of items into a single array while preserving its keys.
|
||||
*
|
||||
* @return static<mixed, mixed>
|
||||
*/
|
||||
public function collapseWithKeys()
|
||||
{
|
||||
if (! $this->items) {
|
||||
return new static;
|
||||
}
|
||||
|
||||
$results = [];
|
||||
|
||||
foreach ($this->items as $key => $values) {
|
||||
if ($values instanceof Collection) {
|
||||
$values = $values->all();
|
||||
} elseif (! is_array($values)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$results[$key] = $values;
|
||||
}
|
||||
|
||||
if (! $results) {
|
||||
return new static;
|
||||
}
|
||||
|
||||
return new static(array_replace(...$results));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an item exists in the collection.
|
||||
*
|
||||
@@ -172,9 +184,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
{
|
||||
if (func_num_args() === 1) {
|
||||
if ($this->useAsCallable($key)) {
|
||||
$placeholder = new stdClass;
|
||||
|
||||
return $this->first($key, $placeholder) !== $placeholder;
|
||||
return array_any($this->items, $key);
|
||||
}
|
||||
|
||||
return in_array($key, $this->items);
|
||||
@@ -216,6 +226,19 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return ! $this->contains(...func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an item is not contained in the enumerable, using strict comparison.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function doesntContainStrict($key, $operator = null, $value = null)
|
||||
{
|
||||
return ! $this->containsStrict(...func_get_args());
|
||||
}
|
||||
|
||||
/**
|
||||
* Cross join with the given lists, returning all possible permutations.
|
||||
*
|
||||
@@ -228,7 +251,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
public function crossJoin(...$lists)
|
||||
{
|
||||
return new static(Arr::crossJoin(
|
||||
$this->items, ...array_map([$this, 'getArrayableItems'], $lists)
|
||||
$this->items, ...array_map($this->getArrayableItems(...), $lists)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -281,7 +304,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Get the items in the collection whose keys are not present in the given items.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @return static
|
||||
*/
|
||||
public function diffKeys($items)
|
||||
@@ -292,7 +315,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Get the items in the collection whose keys are not present in the given items, using the callback.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @param callable(TKey, TKey): int $callback
|
||||
* @return static
|
||||
*/
|
||||
@@ -304,7 +327,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Retrieve duplicate items from the collection.
|
||||
*
|
||||
* @param (callable(TValue): bool)|string|null $callback
|
||||
* @template TMapValue
|
||||
*
|
||||
* @param (callable(TValue): TMapValue)|string|null $callback
|
||||
* @param bool $strict
|
||||
* @return static
|
||||
*/
|
||||
@@ -332,7 +357,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Retrieve duplicate items from the collection using strict comparison.
|
||||
*
|
||||
* @param (callable(TValue): bool)|string|null $callback
|
||||
* @template TMapValue
|
||||
*
|
||||
* @param (callable(TValue): TMapValue)|string|null $callback
|
||||
* @return static
|
||||
*/
|
||||
public function duplicatesStrict($callback = null)
|
||||
@@ -429,8 +456,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Remove an item from the collection by key.
|
||||
*
|
||||
* \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TKey>|TKey $keys
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TKey>|TKey $keys
|
||||
* @return $this
|
||||
*/
|
||||
public function forget($keys)
|
||||
@@ -447,12 +473,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*
|
||||
* @template TGetDefault
|
||||
*
|
||||
* @param TKey $key
|
||||
* @param TKey|null $key
|
||||
* @param TGetDefault|(\Closure(): TGetDefault) $default
|
||||
* @return TValue|TGetDefault
|
||||
*/
|
||||
public function get($key, $default = null)
|
||||
{
|
||||
$key ??= '';
|
||||
|
||||
if (array_key_exists($key, $this->items)) {
|
||||
return $this->items[$key];
|
||||
}
|
||||
@@ -471,8 +499,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*/
|
||||
public function getOrPut($key, $value)
|
||||
{
|
||||
if (array_key_exists($key, $this->items)) {
|
||||
return $this->items[$key];
|
||||
if (array_key_exists($key ?? '', $this->items)) {
|
||||
return $this->items[$key ?? ''];
|
||||
}
|
||||
|
||||
$this->offsetSet($key, $value = value($value));
|
||||
@@ -483,9 +511,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Group an associative array by a field or using a callback.
|
||||
*
|
||||
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
|
||||
* @template TGroupKey of array-key|\UnitEnum|\Stringable
|
||||
*
|
||||
* @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
|
||||
* @param bool $preserveKeys
|
||||
* @return static<array-key, static<array-key, TValue>>
|
||||
* @return static<
|
||||
* ($groupBy is (array|string)
|
||||
* ? array-key
|
||||
* : (TGroupKey is \UnitEnum ? array-key : (TGroupKey is \Stringable ? string : TGroupKey))),
|
||||
* static<($preserveKeys is true ? TKey : int), ($groupBy is array ? mixed : TValue)>
|
||||
* >
|
||||
*/
|
||||
public function groupBy($groupBy, $preserveKeys = false)
|
||||
{
|
||||
@@ -509,8 +544,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
foreach ($groupKeys as $groupKey) {
|
||||
$groupKey = match (true) {
|
||||
is_bool($groupKey) => (int) $groupKey,
|
||||
$groupKey instanceof \BackedEnum => $groupKey->value,
|
||||
$groupKey instanceof \Stringable => (string) $groupKey,
|
||||
$groupKey instanceof \UnitEnum => enum_value($groupKey),
|
||||
$groupKey instanceof \Stringable, is_null($groupKey) => (string) $groupKey,
|
||||
default => $groupKey,
|
||||
};
|
||||
|
||||
@@ -534,8 +569,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Key an associative array by a field or using a callback.
|
||||
*
|
||||
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
|
||||
* @return static<array-key, TValue>
|
||||
* @template TNewKey of array-key|\UnitEnum
|
||||
*
|
||||
* @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
|
||||
* @return static<($keyBy is (array|string) ? array-key : (TNewKey is \UnitEnum ? array-key : TNewKey)), TValue>
|
||||
*/
|
||||
public function keyBy($keyBy)
|
||||
{
|
||||
@@ -546,6 +583,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
foreach ($this->items as $key => $item) {
|
||||
$resolvedKey = $keyBy($item, $key);
|
||||
|
||||
if ($resolvedKey instanceof \UnitEnum) {
|
||||
$resolvedKey = enum_value($resolvedKey);
|
||||
}
|
||||
|
||||
if (is_object($resolvedKey)) {
|
||||
$resolvedKey = (string) $resolvedKey;
|
||||
}
|
||||
@@ -566,19 +607,13 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
{
|
||||
$keys = is_array($key) ? $key : func_get_args();
|
||||
|
||||
foreach ($keys as $value) {
|
||||
if (! array_key_exists($value, $this->items)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
return array_all($keys, fn ($key) => array_key_exists($key ?? '', $this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if any of the keys exist in the collection.
|
||||
*
|
||||
* @param mixed $key
|
||||
* @param TKey|array<array-key, TKey> $key
|
||||
* @return bool
|
||||
*/
|
||||
public function hasAny($key)
|
||||
@@ -589,19 +624,13 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
|
||||
$keys = is_array($key) ? $key : func_get_args();
|
||||
|
||||
foreach ($keys as $value) {
|
||||
if ($this->has($value)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return array_any($keys, fn ($key) => array_key_exists($key ?? '', $this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Concatenate values of a given key as a string.
|
||||
*
|
||||
* @param callable|string $value
|
||||
* @param (callable(TValue, TKey): mixed)|string|null $value
|
||||
* @param string|null $glue
|
||||
* @return string
|
||||
*/
|
||||
@@ -669,7 +698,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Intersect the collection with the given items by key.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @return static
|
||||
*/
|
||||
public function intersectByKeys($items)
|
||||
@@ -682,6 +711,12 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Determine if the collection is empty or not.
|
||||
*
|
||||
* @phpstan-assert-if-true null $this->first()
|
||||
* @phpstan-assert-if-true null $this->last()
|
||||
*
|
||||
* @phpstan-assert-if-false TValue $this->first()
|
||||
* @phpstan-assert-if-false TValue $this->last()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isEmpty()
|
||||
@@ -690,13 +725,29 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the collection contains a single item.
|
||||
* Determine if the collection contains exactly one item. If a callback is provided, determine if exactly one item matches the condition.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|null $callback
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated 12.49.0 Use the `hasSole()` method instead.
|
||||
*/
|
||||
public function containsOneItem()
|
||||
public function containsOneItem(?callable $callback = null): bool
|
||||
{
|
||||
return $this->count() === 1;
|
||||
return $this->hasSole($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the collection contains multiple items.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|null $callback
|
||||
* @return bool
|
||||
*
|
||||
* @deprecated 12.50.0 Use the `hasMany()` method instead.
|
||||
*/
|
||||
public function containsManyItems(?callable $callback = null): bool
|
||||
{
|
||||
return $this->hasMany($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -704,7 +755,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*
|
||||
* @param string $glue
|
||||
* @param string $finalGlue
|
||||
* @return string
|
||||
* @return TValue|string
|
||||
*/
|
||||
public function join($glue, $finalGlue = '')
|
||||
{
|
||||
@@ -756,8 +807,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Get the values of a given key.
|
||||
*
|
||||
* @param string|int|array<array-key, string> $value
|
||||
* @param string|null $key
|
||||
* @param \Closure|string|int|array<array-key, string>|null $value
|
||||
* @param \Closure|string|null $key
|
||||
* @return static<array-key, mixed>
|
||||
*/
|
||||
public function pluck($value, $key = null)
|
||||
@@ -829,8 +880,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Merge the collection with the given items.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @return static
|
||||
* @template TMergeValue
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeValue>|iterable<TKey, TMergeValue> $items
|
||||
* @return static<TKey, TValue|TMergeValue>
|
||||
*/
|
||||
public function merge($items)
|
||||
{
|
||||
@@ -850,6 +903,23 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return new static(array_merge_recursive($this->items, $this->getArrayableItems($items)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Multiply the items in the collection by the multiplier.
|
||||
*
|
||||
* @param int $multiplier
|
||||
* @return static
|
||||
*/
|
||||
public function multiply(int $multiplier)
|
||||
{
|
||||
$new = new static;
|
||||
|
||||
for ($i = 0; $i < $multiplier; $i++) {
|
||||
$new->push(...$this->items);
|
||||
}
|
||||
|
||||
return $new;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a collection by using this collection for keys and another for its values.
|
||||
*
|
||||
@@ -879,10 +949,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*
|
||||
* @param int $step
|
||||
* @param int $offset
|
||||
* @return static
|
||||
* @return ($step is positive-int ? static : never)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function nth($step, $offset = 0)
|
||||
{
|
||||
if ($step < 1) {
|
||||
throw new InvalidArgumentException('Step value must be at least 1.');
|
||||
}
|
||||
|
||||
$new = [];
|
||||
|
||||
$position = 0;
|
||||
@@ -944,10 +1020,14 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
* Get and remove the last N items from the collection.
|
||||
*
|
||||
* @param int $count
|
||||
* @return static<int, TValue>|TValue|null
|
||||
* @return ($count is 1 ? TValue|null : static<int, TValue>)
|
||||
*/
|
||||
public function pop($count = 1)
|
||||
{
|
||||
if ($count < 1) {
|
||||
return new static;
|
||||
}
|
||||
|
||||
if ($count === 1) {
|
||||
return array_pop($this->items);
|
||||
}
|
||||
@@ -961,7 +1041,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
$collectionCount = $this->count();
|
||||
|
||||
foreach (range(1, min($count, $collectionCount)) as $item) {
|
||||
array_push($results, array_pop($this->items));
|
||||
$results[] = array_pop($this->items);
|
||||
}
|
||||
|
||||
return new static($results);
|
||||
@@ -976,7 +1056,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*/
|
||||
public function prepend($value, $key = null)
|
||||
{
|
||||
$this->items = Arr::prepend($this->items, ...func_get_args());
|
||||
$this->items = Arr::prepend($this->items, ...(func_num_args() > 1 ? func_get_args() : [$value]));
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -996,6 +1076,19 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prepend one or more items to the beginning of the collection.
|
||||
*
|
||||
* @param TValue ...$values
|
||||
* @return $this
|
||||
*/
|
||||
public function unshift(...$values)
|
||||
{
|
||||
array_unshift($this->items, ...$values);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Push all of the given items onto the collection.
|
||||
*
|
||||
@@ -1049,7 +1142,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
*
|
||||
* @param (callable(self<TKey, TValue>): int)|int|null $number
|
||||
* @param bool $preserveKeys
|
||||
* @return static<int, TValue>|TValue
|
||||
* @return ($number is null ? TValue : static<int, TValue>)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@@ -1111,20 +1204,62 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return array_search($value, $this->items, $strict);
|
||||
}
|
||||
|
||||
foreach ($this->items as $key => $item) {
|
||||
if ($value($item, $key)) {
|
||||
return $key;
|
||||
}
|
||||
return array_find_key($this->items, $value) ?? false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item before the given item.
|
||||
*
|
||||
* @param TValue|(callable(TValue,TKey): bool) $value
|
||||
* @param bool $strict
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function before($value, $strict = false)
|
||||
{
|
||||
$key = $this->search($value, $strict);
|
||||
|
||||
if ($key === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return false;
|
||||
$position = ($keys = $this->keys())->search($key);
|
||||
|
||||
if ($position === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->get($keys->get($position - 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the item after the given item.
|
||||
*
|
||||
* @param TValue|(callable(TValue,TKey): bool) $value
|
||||
* @param bool $strict
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function after($value, $strict = false)
|
||||
{
|
||||
$key = $this->search($value, $strict);
|
||||
|
||||
if ($key === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$position = ($keys = $this->keys())->search($key);
|
||||
|
||||
if ($position === $keys->count() - 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->get($keys->get($position + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get and remove the first N items from the collection.
|
||||
*
|
||||
* @param int $count
|
||||
* @return static<int, TValue>|TValue|null
|
||||
* @param int<0, max> $count
|
||||
* @return ($count is 1 ? TValue|null : static<int, TValue>)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@@ -1151,7 +1286,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
$collectionCount = $this->count();
|
||||
|
||||
foreach (range(1, min($count, $collectionCount)) as $item) {
|
||||
array_push($results, array_shift($this->items));
|
||||
$results[] = array_shift($this->items);
|
||||
}
|
||||
|
||||
return new static($results);
|
||||
@@ -1160,23 +1295,30 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Shuffle the items in the collection.
|
||||
*
|
||||
* @param int|null $seed
|
||||
* @return static
|
||||
*/
|
||||
public function shuffle($seed = null)
|
||||
public function shuffle()
|
||||
{
|
||||
return new static(Arr::shuffle($this->items, $seed));
|
||||
return new static(Arr::shuffle($this->items));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create chunks representing a "sliding window" view of the items in the collection.
|
||||
*
|
||||
* @param int $size
|
||||
* @param int $step
|
||||
* @param positive-int $size
|
||||
* @param positive-int $step
|
||||
* @return static<int, static>
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function sliding($size = 2, $step = 1)
|
||||
{
|
||||
if ($size < 1) {
|
||||
throw new InvalidArgumentException('Size value must be at least 1.');
|
||||
} elseif ($step < 1) {
|
||||
throw new InvalidArgumentException('Step value must be at least 1.');
|
||||
}
|
||||
|
||||
$chunks = floor(($this->count() - $size) / $step) + 1;
|
||||
|
||||
return static::times($chunks, fn ($number) => $this->slice(($number - 1) * $step, $size));
|
||||
@@ -1231,10 +1373,16 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
* Split a collection into a certain number of groups.
|
||||
*
|
||||
* @param int $numberOfGroups
|
||||
* @return static<int, static>
|
||||
* @return ($numberOfGroups is positive-int ? static<int, static> : never)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function split($numberOfGroups)
|
||||
{
|
||||
if ($numberOfGroups < 1) {
|
||||
throw new InvalidArgumentException('Number of groups must be at least 1.');
|
||||
}
|
||||
|
||||
if ($this->isEmpty()) {
|
||||
return new static;
|
||||
}
|
||||
@@ -1268,17 +1416,23 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
* Split a collection into a certain number of groups, and fill the first groups completely.
|
||||
*
|
||||
* @param int $numberOfGroups
|
||||
* @return static<int, static>
|
||||
* @return ($numberOfGroups is positive-int ? static<int, static> : never)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function splitIn($numberOfGroups)
|
||||
{
|
||||
return $this->chunk(ceil($this->count() / $numberOfGroups));
|
||||
if ($numberOfGroups < 1) {
|
||||
throw new InvalidArgumentException('Number of groups must be at least 1.');
|
||||
}
|
||||
|
||||
return $this->chunk((int) ceil($this->count() / $numberOfGroups));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first item in the collection, but only if exactly one item exists. Otherwise, throw an exception.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|string $key
|
||||
* @param (callable(TValue, TKey): bool)|string|null $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return TValue
|
||||
@@ -1307,6 +1461,26 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
return $items->first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the collection contains a single item, optionally matching the given criteria.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|string|null $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function hasSole($key = null, $operator = null, $value = null): bool
|
||||
{
|
||||
$filter = func_num_args() > 1
|
||||
? $this->operatorForWhere(...func_get_args())
|
||||
: $key;
|
||||
|
||||
return $this
|
||||
->unless($filter == null)
|
||||
->filter($filter)
|
||||
->count() === 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the first item in the collection but throw an exception if no matching items exist.
|
||||
*
|
||||
@@ -1338,9 +1512,10 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
* Chunk the collection into chunks of the given size.
|
||||
*
|
||||
* @param int $size
|
||||
* @return static<int, static>
|
||||
* @param bool $preserveKeys
|
||||
* @return ($preserveKeys is true ? static<int, static> : static<int, static<int, TValue>>)
|
||||
*/
|
||||
public function chunk($size)
|
||||
public function chunk($size, $preserveKeys = true)
|
||||
{
|
||||
if ($size <= 0) {
|
||||
return new static;
|
||||
@@ -1348,7 +1523,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
|
||||
$chunks = [];
|
||||
|
||||
foreach (array_chunk($this->items, $size, true) as $chunk) {
|
||||
foreach (array_chunk($this->items, $size, $preserveKeys) as $chunk) {
|
||||
$chunks[] = new static($chunk);
|
||||
}
|
||||
|
||||
@@ -1358,8 +1533,8 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Chunk the collection into chunks with a callback.
|
||||
*
|
||||
* @param callable(TValue, TKey, static<int, TValue>): bool $callback
|
||||
* @return static<int, static<int, TValue>>
|
||||
* @param callable(TValue, TKey, static<TKey, TValue>): bool $callback
|
||||
* @return static<int, static<TKey, TValue>>
|
||||
*/
|
||||
public function chunkWhile(callable $callback)
|
||||
{
|
||||
@@ -1475,9 +1650,9 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
}
|
||||
} else {
|
||||
$result = match ($options) {
|
||||
SORT_NUMERIC => intval($values[0]) <=> intval($values[1]),
|
||||
SORT_NUMERIC => (int) $values[0] <=> (int) $values[1],
|
||||
SORT_STRING => strcmp($values[0], $values[1]),
|
||||
SORT_NATURAL => strnatcmp($values[0], $values[1]),
|
||||
SORT_NATURAL => strnatcmp((string) $values[0], (string) $values[1]),
|
||||
SORT_LOCALE_STRING => strcoll($values[0], $values[1]),
|
||||
default => $values[0] <=> $values[1],
|
||||
};
|
||||
@@ -1616,8 +1791,12 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Transform each item in the collection using a callback.
|
||||
*
|
||||
* @param callable(TValue, TKey): TValue $callback
|
||||
* @template TMapValue
|
||||
*
|
||||
* @param callable(TValue, TKey): TMapValue $callback
|
||||
* @return $this
|
||||
*
|
||||
* @phpstan-this-out static<TKey, TMapValue>
|
||||
*/
|
||||
public function transform(callable $callback)
|
||||
{
|
||||
@@ -1629,11 +1808,12 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Flatten a multi-dimensional associative array with dots.
|
||||
*
|
||||
* @param int $depth
|
||||
* @return static
|
||||
*/
|
||||
public function dot()
|
||||
public function dot($depth = INF)
|
||||
{
|
||||
return new static(Arr::dot($this->all()));
|
||||
return new static(Arr::dot($this->all(), '', $depth));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1729,7 +1909,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Count the number of items in the collection.
|
||||
*
|
||||
* @return int
|
||||
* @return int<0, max>
|
||||
*/
|
||||
public function count(): int
|
||||
{
|
||||
@@ -1739,7 +1919,7 @@ class Collection implements ArrayAccess, CanBeEscapedWhenCastToString, Enumerabl
|
||||
/**
|
||||
* Count the number of items in the collection by a field or using a callback.
|
||||
*
|
||||
* @param (callable(TValue, TKey): array-key)|string|null $countBy
|
||||
* @param (callable(TValue, TKey): (array-key|\UnitEnum))|string|null $countBy
|
||||
* @return static<array-key, int>
|
||||
*/
|
||||
public function countBy($countBy = null)
|
||||
|
||||
+85
-18
@@ -45,9 +45,10 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*
|
||||
* @param int $from
|
||||
* @param int $to
|
||||
* @param int $step
|
||||
* @return static
|
||||
*/
|
||||
public static function range($from, $to);
|
||||
public static function range($from, $to, $step = 1);
|
||||
|
||||
/**
|
||||
* Wrap the given value in a collection if applicable.
|
||||
@@ -184,9 +185,10 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Dump the collection.
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return $this
|
||||
*/
|
||||
public function dump();
|
||||
public function dump(...$args);
|
||||
|
||||
/**
|
||||
* Get the items that are not present in the given items.
|
||||
@@ -225,7 +227,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Get the items whose keys are not present in the given items.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @return static
|
||||
*/
|
||||
public function diffKeys($items);
|
||||
@@ -233,7 +235,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Get the items whose keys are not present in the given items, using the callback.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @param callable(TKey, TKey): int $callback
|
||||
* @return static
|
||||
*/
|
||||
@@ -333,7 +335,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
public function whenNotEmpty(callable $callback, ?callable $default = null);
|
||||
|
||||
/**
|
||||
* Apply the callback if the given "value" is (or resolves to) truthy.
|
||||
* Apply the callback if the given "value" is (or resolves to) falsy.
|
||||
*
|
||||
* @template TUnlessReturnType
|
||||
*
|
||||
@@ -517,17 +519,21 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Group an associative array by a field or using a callback.
|
||||
*
|
||||
* @param (callable(TValue, TKey): array-key)|array|string $groupBy
|
||||
* @template TGroupKey of array-key
|
||||
*
|
||||
* @param (callable(TValue, TKey): TGroupKey)|array|string $groupBy
|
||||
* @param bool $preserveKeys
|
||||
* @return static<array-key, static<array-key, TValue>>
|
||||
* @return static<($groupBy is string ? array-key : ($groupBy is array ? array-key : TGroupKey)), static<($preserveKeys is true ? TKey : int), ($groupBy is array ? mixed : TValue)>>
|
||||
*/
|
||||
public function groupBy($groupBy, $preserveKeys = false);
|
||||
|
||||
/**
|
||||
* Key an associative array by a field or using a callback.
|
||||
*
|
||||
* @param (callable(TValue, TKey): array-key)|array|string $keyBy
|
||||
* @return static<array-key, TValue>
|
||||
* @template TNewKey of array-key
|
||||
*
|
||||
* @param (callable(TValue, TKey): TNewKey)|array|string $keyBy
|
||||
* @return static<($keyBy is string ? array-key : ($keyBy is array ? array-key : TNewKey)), TValue>
|
||||
*/
|
||||
public function keyBy($keyBy);
|
||||
|
||||
@@ -550,7 +556,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Concatenate values of a given key as a string.
|
||||
*
|
||||
* @param callable|string $value
|
||||
* @param (callable(TValue, TKey): mixed)|string $value
|
||||
* @param string|null $glue
|
||||
* @return string
|
||||
*/
|
||||
@@ -565,11 +571,37 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
public function intersect($items);
|
||||
|
||||
/**
|
||||
* Intersect the collection with the given items by key.
|
||||
* Intersect the collection with the given items, using the callback.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
|
||||
* @param callable(TValue, TValue): int $callback
|
||||
* @return static
|
||||
*/
|
||||
public function intersectUsing($items, callable $callback);
|
||||
|
||||
/**
|
||||
* Intersect the collection with the given items with additional index check.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @return static
|
||||
*/
|
||||
public function intersectAssoc($items);
|
||||
|
||||
/**
|
||||
* Intersect the collection with the given items with additional index check, using the callback.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<array-key, TValue>|iterable<array-key, TValue> $items
|
||||
* @param callable(TValue, TValue): int $callback
|
||||
* @return static
|
||||
*/
|
||||
public function intersectAssocUsing($items, callable $callback);
|
||||
|
||||
/**
|
||||
* Intersect the collection with the given items by key.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, mixed>|iterable<TKey, mixed> $items
|
||||
* @return static
|
||||
*/
|
||||
public function intersectByKeys($items);
|
||||
|
||||
/**
|
||||
@@ -593,6 +625,13 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*/
|
||||
public function containsOneItem();
|
||||
|
||||
/**
|
||||
* Determine if the collection contains multiple items.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function containsManyItems();
|
||||
|
||||
/**
|
||||
* Join all items from the collection using a string. The final items can use a separate glue string.
|
||||
*
|
||||
@@ -701,8 +740,10 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Merge the collection with the given items.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue> $items
|
||||
* @return static
|
||||
* @template TMergeValue
|
||||
*
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TMergeValue>|iterable<TKey, TMergeValue> $items
|
||||
* @return static<TKey, TValue|TMergeValue>
|
||||
*/
|
||||
public function merge($items);
|
||||
|
||||
@@ -815,7 +856,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*
|
||||
* @param callable(TReduceInitial|TReduceReturnType, TValue, TKey): TReduceReturnType $callback
|
||||
* @param TReduceInitial $initial
|
||||
* @return TReduceReturnType
|
||||
* @return TReduceInitial|TReduceReturnType
|
||||
*/
|
||||
public function reduce(callable $callback, $initial = null);
|
||||
|
||||
@@ -862,13 +903,30 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*/
|
||||
public function search($value, $strict = false);
|
||||
|
||||
/**
|
||||
* Get the item before the given item.
|
||||
*
|
||||
* @param TValue|(callable(TValue,TKey): bool) $value
|
||||
* @param bool $strict
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function before($value, $strict = false);
|
||||
|
||||
/**
|
||||
* Get the item after the given item.
|
||||
*
|
||||
* @param TValue|(callable(TValue,TKey): bool) $value
|
||||
* @param bool $strict
|
||||
* @return TValue|null
|
||||
*/
|
||||
public function after($value, $strict = false);
|
||||
|
||||
/**
|
||||
* Shuffle the items in the collection.
|
||||
*
|
||||
* @param int|null $seed
|
||||
* @return static
|
||||
*/
|
||||
public function shuffle($seed = null);
|
||||
public function shuffle();
|
||||
|
||||
/**
|
||||
* Create chunks representing a "sliding window" view of the items in the collection.
|
||||
@@ -936,7 +994,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
/**
|
||||
* Get the first item in the collection but throw an exception if no matching items exist.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|string $key
|
||||
* @param (callable(TValue, TKey): bool)|string|null $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return TValue
|
||||
@@ -1102,7 +1160,7 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*
|
||||
* @param string|array<array-key, string> $value
|
||||
* @param string|null $key
|
||||
* @return static<int, mixed>
|
||||
* @return static<array-key, mixed>
|
||||
*/
|
||||
public function pluck($value, $key = null);
|
||||
|
||||
@@ -1220,6 +1278,15 @@ interface Enumerable extends Arrayable, Countable, IteratorAggregate, Jsonable,
|
||||
*/
|
||||
public function toJson($options = 0);
|
||||
|
||||
/**
|
||||
* Get the collection of items as pretty print formatted JSON.
|
||||
*
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toPrettyJson(int $options = 0);
|
||||
|
||||
/**
|
||||
* Get a CachingIterator instance.
|
||||
*
|
||||
|
||||
+11
-5
@@ -3,14 +3,19 @@
|
||||
namespace Illuminate\Support;
|
||||
|
||||
/**
|
||||
* @mixin \Illuminate\Support\Enumerable
|
||||
* @template TKey of array-key
|
||||
*
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @mixin \Illuminate\Support\Enumerable<TKey, TValue>
|
||||
* @mixin TValue
|
||||
*/
|
||||
class HigherOrderCollectionProxy
|
||||
{
|
||||
/**
|
||||
* The collection being operated on.
|
||||
*
|
||||
* @var \Illuminate\Support\Enumerable
|
||||
* @var \Illuminate\Support\Enumerable<TKey, TValue>
|
||||
*/
|
||||
protected $collection;
|
||||
|
||||
@@ -24,9 +29,8 @@ class HigherOrderCollectionProxy
|
||||
/**
|
||||
* Create a new proxy instance.
|
||||
*
|
||||
* @param \Illuminate\Support\Enumerable $collection
|
||||
* @param \Illuminate\Support\Enumerable<TKey, TValue> $collection
|
||||
* @param string $method
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Enumerable $collection, $method)
|
||||
{
|
||||
@@ -57,7 +61,9 @@ class HigherOrderCollectionProxy
|
||||
public function __call($method, $parameters)
|
||||
{
|
||||
return $this->collection->{$this->method}(function ($value) use ($method, $parameters) {
|
||||
return $value->{$method}(...$parameters);
|
||||
return is_string($value)
|
||||
? $value::{$method}(...$parameters)
|
||||
: $value->{$method}(...$parameters);
|
||||
});
|
||||
}
|
||||
}
|
||||
+437
-248
File diff suppressed because it is too large.
Load diff
-1
@@ -19,7 +19,6 @@ class MultipleItemsFoundException extends RuntimeException
|
||||
* @param int $count
|
||||
* @param int $code
|
||||
* @param \Throwable|null $previous
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($count, $code = 0, $previous = null)
|
||||
{
|
||||
|
||||
+158
-97
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Illuminate\Support\Traits;
|
||||
|
||||
use BackedEnum;
|
||||
use CachingIterator;
|
||||
use Closure;
|
||||
use Exception;
|
||||
@@ -11,48 +12,49 @@ use Illuminate\Support\Arr;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Enumerable;
|
||||
use Illuminate\Support\HigherOrderCollectionProxy;
|
||||
use InvalidArgumentException;
|
||||
use JsonSerializable;
|
||||
use Symfony\Component\VarDumper\VarDumper;
|
||||
use Traversable;
|
||||
use UnexpectedValueException;
|
||||
use UnitEnum;
|
||||
use WeakMap;
|
||||
|
||||
use function Illuminate\Support\enum_value;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
*
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @property-read HigherOrderCollectionProxy $average
|
||||
* @property-read HigherOrderCollectionProxy $avg
|
||||
* @property-read HigherOrderCollectionProxy $contains
|
||||
* @property-read HigherOrderCollectionProxy $doesntContain
|
||||
* @property-read HigherOrderCollectionProxy $each
|
||||
* @property-read HigherOrderCollectionProxy $every
|
||||
* @property-read HigherOrderCollectionProxy $filter
|
||||
* @property-read HigherOrderCollectionProxy $first
|
||||
* @property-read HigherOrderCollectionProxy $flatMap
|
||||
* @property-read HigherOrderCollectionProxy $groupBy
|
||||
* @property-read HigherOrderCollectionProxy $keyBy
|
||||
* @property-read HigherOrderCollectionProxy $map
|
||||
* @property-read HigherOrderCollectionProxy $max
|
||||
* @property-read HigherOrderCollectionProxy $min
|
||||
* @property-read HigherOrderCollectionProxy $partition
|
||||
* @property-read HigherOrderCollectionProxy $percentage
|
||||
* @property-read HigherOrderCollectionProxy $reject
|
||||
* @property-read HigherOrderCollectionProxy $skipUntil
|
||||
* @property-read HigherOrderCollectionProxy $skipWhile
|
||||
* @property-read HigherOrderCollectionProxy $some
|
||||
* @property-read HigherOrderCollectionProxy $sortBy
|
||||
* @property-read HigherOrderCollectionProxy $sortByDesc
|
||||
* @property-read HigherOrderCollectionProxy $sum
|
||||
* @property-read HigherOrderCollectionProxy $takeUntil
|
||||
* @property-read HigherOrderCollectionProxy $takeWhile
|
||||
* @property-read HigherOrderCollectionProxy $unique
|
||||
* @property-read HigherOrderCollectionProxy $unless
|
||||
* @property-read HigherOrderCollectionProxy $until
|
||||
* @property-read HigherOrderCollectionProxy $when
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $average
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $avg
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $contains
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $doesntContain
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $each
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $every
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $filter
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $first
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $flatMap
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $groupBy
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $hasMany
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $hasSole
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $keyBy
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $last
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $map
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $max
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $min
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $partition
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $percentage
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $reject
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $skipUntil
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $skipWhile
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $some
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $sortBy
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $sortByDesc
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $sum
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $takeUntil
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $takeWhile
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $unique
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $unless
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $until
|
||||
* @property-read HigherOrderCollectionProxy<TKey, TValue> $when
|
||||
*/
|
||||
trait EnumeratesValues
|
||||
{
|
||||
@@ -81,7 +83,10 @@ trait EnumeratesValues
|
||||
'first',
|
||||
'flatMap',
|
||||
'groupBy',
|
||||
'hasMany',
|
||||
'hasSole',
|
||||
'keyBy',
|
||||
'last',
|
||||
'map',
|
||||
'max',
|
||||
'min',
|
||||
@@ -175,6 +180,41 @@ trait EnumeratesValues
|
||||
->map($callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new collection by decoding a JSON string.
|
||||
*
|
||||
* @param string $json
|
||||
* @param int $depth
|
||||
* @param int $flags
|
||||
* @return static<TKey, TValue>
|
||||
*/
|
||||
public static function fromJson($json, $depth = 512, $flags = 0)
|
||||
{
|
||||
return new static(json_decode($json, true, $depth, $flags));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the average value of a given key.
|
||||
*
|
||||
* @param (callable(TValue): float|int)|string|null $callback
|
||||
* @return float|int|null
|
||||
*/
|
||||
public function avg($callback = null)
|
||||
{
|
||||
$callback = $this->valueRetriever($callback);
|
||||
|
||||
$reduced = $this->reduce(static function (&$reduce, $value) use ($callback) {
|
||||
if (! is_null($resolved = $callback($value))) {
|
||||
$reduce[0] += $resolved;
|
||||
$reduce[1]++;
|
||||
}
|
||||
|
||||
return $reduce;
|
||||
}, [0, 0]);
|
||||
|
||||
return $reduced[1] ? $reduced[0] / $reduced[1] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Alias for the "avg" method.
|
||||
*
|
||||
@@ -200,30 +240,25 @@ trait EnumeratesValues
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the items and end the script.
|
||||
* Dump the given arguments and terminate execution.
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return never
|
||||
*/
|
||||
public function dd(...$args)
|
||||
{
|
||||
$this->dump(...$args);
|
||||
|
||||
exit(1);
|
||||
dd($this->all(), ...$args);
|
||||
}
|
||||
|
||||
/**
|
||||
* Dump the items.
|
||||
*
|
||||
* @param mixed ...$args
|
||||
* @return $this
|
||||
*/
|
||||
public function dump()
|
||||
public function dump(...$args)
|
||||
{
|
||||
(new Collection(func_get_args()))
|
||||
->push($this->all())
|
||||
->each(function ($item) {
|
||||
VarDumper::dump($item);
|
||||
});
|
||||
dump($this->all(), ...$args);
|
||||
|
||||
return $this;
|
||||
}
|
||||
@@ -298,6 +333,27 @@ trait EnumeratesValues
|
||||
return $this->first($this->operatorForWhere(...func_get_args()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the collection contains multiple items, optionally matching the given criteria.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|string|null $key
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMany($key = null, $operator = null, $value = null): bool
|
||||
{
|
||||
$filter = func_num_args() > 1
|
||||
? $this->operatorForWhere(...func_get_args())
|
||||
: $key;
|
||||
|
||||
return $this
|
||||
->unless($filter == null)
|
||||
->filter($filter)
|
||||
->take(2)
|
||||
->count() === 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single key's value from the first matching item in the collection.
|
||||
*
|
||||
@@ -309,11 +365,11 @@ trait EnumeratesValues
|
||||
*/
|
||||
public function value($key, $default = null)
|
||||
{
|
||||
if ($value = $this->firstWhere($key)) {
|
||||
return data_get($value, $key, $default);
|
||||
}
|
||||
$value = $this->first(function ($target) use ($key) {
|
||||
return data_has($target, $key);
|
||||
});
|
||||
|
||||
return value($default);
|
||||
return data_get($value, $key, $default);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -321,7 +377,7 @@ trait EnumeratesValues
|
||||
*
|
||||
* @template TEnsureOfType
|
||||
*
|
||||
* @param class-string<TEnsureOfType>|array<array-key, class-string<TEnsureOfType>> $type
|
||||
* @param class-string<TEnsureOfType>|array<array-key, class-string<TEnsureOfType>>|'string'|'int'|'float'|'bool'|'array'|'null' $type
|
||||
* @return static<TKey, TEnsureOfType>
|
||||
*
|
||||
* @throws \UnexpectedValueException
|
||||
@@ -330,7 +386,7 @@ trait EnumeratesValues
|
||||
{
|
||||
$allowedTypes = is_array($type) ? $type : [$type];
|
||||
|
||||
return $this->each(function ($item) use ($allowedTypes) {
|
||||
return $this->each(function ($item, $index) use ($allowedTypes) {
|
||||
$itemType = get_debug_type($item);
|
||||
|
||||
foreach ($allowedTypes as $allowedType) {
|
||||
@@ -340,7 +396,7 @@ trait EnumeratesValues
|
||||
}
|
||||
|
||||
throw new UnexpectedValueException(
|
||||
sprintf("Collection should only include [%s] items, but '%s' found.", implode(', ', $allowedTypes), $itemType)
|
||||
sprintf("Collection should only include [%s] items, but '%s' found at position %d.", implode(', ', $allowedTypes), $itemType, $index)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -348,6 +404,12 @@ trait EnumeratesValues
|
||||
/**
|
||||
* Determine if the collection is not empty.
|
||||
*
|
||||
* @phpstan-assert-if-true TValue $this->first()
|
||||
* @phpstan-assert-if-true TValue $this->last()
|
||||
*
|
||||
* @phpstan-assert-if-false null $this->first()
|
||||
* @phpstan-assert-if-false null $this->last()
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isNotEmpty()
|
||||
@@ -387,7 +449,7 @@ trait EnumeratesValues
|
||||
{
|
||||
$groups = $this->mapToDictionary($callback);
|
||||
|
||||
return $groups->map([$this, 'make']);
|
||||
return $groups->map($this->make(...));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -414,6 +476,10 @@ trait EnumeratesValues
|
||||
*/
|
||||
public function mapInto($class)
|
||||
{
|
||||
if (is_subclass_of($class, BackedEnum::class)) {
|
||||
return $this->map(fn ($value, $key) => $class::from($value));
|
||||
}
|
||||
|
||||
return $this->map(fn ($value, $key) => new $class($value, $key));
|
||||
}
|
||||
|
||||
@@ -428,7 +494,7 @@ trait EnumeratesValues
|
||||
$callback = $this->valueRetriever($callback);
|
||||
|
||||
return $this->map(fn ($value) => $callback($value))
|
||||
->filter(fn ($value) => ! is_null($value))
|
||||
->reject(fn ($value) => is_null($value))
|
||||
->reduce(fn ($result, $value) => is_null($result) || $value < $result ? $value : $result);
|
||||
}
|
||||
|
||||
@@ -442,7 +508,7 @@ trait EnumeratesValues
|
||||
{
|
||||
$callback = $this->valueRetriever($callback);
|
||||
|
||||
return $this->filter(fn ($value) => ! is_null($value))->reduce(function ($result, $item) use ($callback) {
|
||||
return $this->reject(fn ($value) => is_null($value))->reduce(function ($result, $item) use ($callback) {
|
||||
$value = $callback($item);
|
||||
|
||||
return is_null($result) || $value > $result ? $value : $result;
|
||||
@@ -467,26 +533,17 @@ trait EnumeratesValues
|
||||
* Partition the collection into two arrays using the given callback or key.
|
||||
*
|
||||
* @param (callable(TValue, TKey): bool)|TValue|string $key
|
||||
* @param TValue|string|null $operator
|
||||
* @param TValue|null $value
|
||||
* @param mixed $operator
|
||||
* @param mixed $value
|
||||
* @return static<int<0, 1>, static<TKey, TValue>>
|
||||
*/
|
||||
public function partition($key, $operator = null, $value = null)
|
||||
{
|
||||
$passed = [];
|
||||
$failed = [];
|
||||
|
||||
$callback = func_num_args() === 1
|
||||
? $this->valueRetriever($key)
|
||||
: $this->operatorForWhere(...func_get_args());
|
||||
? $this->valueRetriever($key)
|
||||
: $this->operatorForWhere(...func_get_args());
|
||||
|
||||
foreach ($this as $key => $item) {
|
||||
if ($callback($item, $key)) {
|
||||
$passed[$key] = $item;
|
||||
} else {
|
||||
$failed[$key] = $item;
|
||||
}
|
||||
}
|
||||
[$passed, $failed] = Arr::partition($this->getIterator(), $callback);
|
||||
|
||||
return new static([new static($passed), new static($failed)]);
|
||||
}
|
||||
@@ -513,8 +570,10 @@ trait EnumeratesValues
|
||||
/**
|
||||
* Get the sum of the given values.
|
||||
*
|
||||
* @param (callable(TValue): mixed)|string|null $callback
|
||||
* @return mixed
|
||||
* @template TReturnType
|
||||
*
|
||||
* @param (callable(TValue): TReturnType)|string|null $callback
|
||||
* @return ($callback is callable ? TReturnType : mixed)
|
||||
*/
|
||||
public function sum($callback = null)
|
||||
{
|
||||
@@ -767,7 +826,7 @@ trait EnumeratesValues
|
||||
*/
|
||||
public function pipeThrough($callbacks)
|
||||
{
|
||||
return Collection::make($callbacks)->reduce(
|
||||
return (new Collection($callbacks))->reduce(
|
||||
fn ($carry, $callback) => $callback($carry),
|
||||
$this,
|
||||
);
|
||||
@@ -927,15 +986,12 @@ trait EnumeratesValues
|
||||
public function jsonSerialize(): array
|
||||
{
|
||||
return array_map(function ($value) {
|
||||
if ($value instanceof JsonSerializable) {
|
||||
return $value->jsonSerialize();
|
||||
} elseif ($value instanceof Jsonable) {
|
||||
return json_decode($value->toJson(), true);
|
||||
} elseif ($value instanceof Arrayable) {
|
||||
return $value->toArray();
|
||||
}
|
||||
|
||||
return $value;
|
||||
return match (true) {
|
||||
$value instanceof JsonSerializable => $value->jsonSerialize(),
|
||||
$value instanceof Jsonable => json_decode($value->toJson(), true),
|
||||
$value instanceof Arrayable => $value->toArray(),
|
||||
default => $value,
|
||||
};
|
||||
}, $this->all());
|
||||
}
|
||||
|
||||
@@ -950,6 +1006,17 @@ trait EnumeratesValues
|
||||
return json_encode($this->jsonSerialize(), $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the collection of items as pretty print formatted JSON.
|
||||
*
|
||||
* @param int $options
|
||||
* @return string
|
||||
*/
|
||||
public function toPrettyJson(int $options = 0)
|
||||
{
|
||||
return $this->toJson(JSON_PRETTY_PRINT | $options);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a CachingIterator instance.
|
||||
*
|
||||
@@ -969,8 +1036,8 @@ trait EnumeratesValues
|
||||
public function __toString()
|
||||
{
|
||||
return $this->escapeWhenCastingToString
|
||||
? e($this->toJson())
|
||||
: $this->toJson();
|
||||
? e($this->toJson())
|
||||
: $this->toJson();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1022,20 +1089,9 @@ trait EnumeratesValues
|
||||
*/
|
||||
protected function getArrayableItems($items)
|
||||
{
|
||||
if (is_array($items)) {
|
||||
return $items;
|
||||
}
|
||||
|
||||
return match (true) {
|
||||
$items instanceof WeakMap => throw new InvalidArgumentException('Collections can not be created using instances of WeakMap.'),
|
||||
$items instanceof Enumerable => $items->all(),
|
||||
$items instanceof Arrayable => $items->toArray(),
|
||||
$items instanceof Traversable => iterator_to_array($items),
|
||||
$items instanceof Jsonable => json_decode($items->toJson(), true),
|
||||
$items instanceof JsonSerializable => (array) $items->jsonSerialize(),
|
||||
$items instanceof UnitEnum => [$items],
|
||||
default => (array) $items,
|
||||
};
|
||||
return is_null($items) || is_scalar($items) || $items instanceof UnitEnum
|
||||
? Arr::wrap($items)
|
||||
: Arr::from($items);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1065,10 +1121,15 @@ trait EnumeratesValues
|
||||
}
|
||||
|
||||
return function ($item) use ($key, $operator, $value) {
|
||||
$retrieved = data_get($item, $key);
|
||||
$retrieved = enum_value(data_get($item, $key));
|
||||
$value = enum_value($value);
|
||||
|
||||
$strings = array_filter([$retrieved, $value], function ($value) {
|
||||
return is_string($value) || (is_object($value) && method_exists($value, '__toString'));
|
||||
return match (true) {
|
||||
is_string($value) => true,
|
||||
$value instanceof \Stringable => true,
|
||||
default => false,
|
||||
};
|
||||
});
|
||||
|
||||
if (count($strings) < 2 && count(array_filter([$retrieved, $value], 'is_object')) == 1) {
|
||||
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Support\Traits;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\UseResource;
|
||||
use Illuminate\Database\Eloquent\Attributes\UseResourceCollection;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use LogicException;
|
||||
use ReflectionClass;
|
||||
|
||||
trait TransformsToResourceCollection
|
||||
{
|
||||
/**
|
||||
* Create a new resource collection instance for the given resource.
|
||||
*
|
||||
* @param class-string<\Illuminate\Http\Resources\Json\JsonResource>|null $resourceClass
|
||||
* @return \Illuminate\Http\Resources\Json\ResourceCollection
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
public function toResourceCollection(?string $resourceClass = null): ResourceCollection
|
||||
{
|
||||
if ($resourceClass === null) {
|
||||
return $this->guessResourceCollection();
|
||||
}
|
||||
|
||||
return $resourceClass::collection($this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Guess the resource collection for the items.
|
||||
*
|
||||
* @return \Illuminate\Http\Resources\Json\ResourceCollection
|
||||
*
|
||||
* @throws \Throwable
|
||||
*/
|
||||
protected function guessResourceCollection(): ResourceCollection
|
||||
{
|
||||
if ($this->isEmpty()) {
|
||||
return new ResourceCollection($this);
|
||||
}
|
||||
|
||||
$model = $this->items[0] ?? null;
|
||||
|
||||
throw_unless(is_object($model), LogicException::class, 'Resource collection guesser expects the collection to contain objects.');
|
||||
|
||||
/** @var class-string<Model> $className */
|
||||
$className = get_class($model);
|
||||
|
||||
throw_unless(method_exists($className, 'guessResourceName'), LogicException::class, sprintf('Expected class %s to implement guessResourceName method. Make sure the model uses the TransformsToResource trait.', $className));
|
||||
|
||||
$useResourceCollection = $this->resolveResourceCollectionFromAttribute($className);
|
||||
|
||||
if ($useResourceCollection !== null && class_exists($useResourceCollection)) {
|
||||
return new $useResourceCollection($this);
|
||||
}
|
||||
|
||||
$useResource = $this->resolveResourceFromAttribute($className);
|
||||
|
||||
if ($useResource !== null && class_exists($useResource)) {
|
||||
return $useResource::collection($this);
|
||||
}
|
||||
|
||||
$resourceClasses = $className::guessResourceName();
|
||||
|
||||
foreach ($resourceClasses as $resourceClass) {
|
||||
$resourceCollection = $resourceClass.'Collection';
|
||||
|
||||
if (is_string($resourceCollection) && class_exists($resourceCollection)) {
|
||||
return new $resourceCollection($this);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($resourceClasses as $resourceClass) {
|
||||
if (is_string($resourceClass) && class_exists($resourceClass)) {
|
||||
return $resourceClass::collection($this);
|
||||
}
|
||||
}
|
||||
|
||||
throw new LogicException(sprintf('Failed to find resource class for model [%s].', $className));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource class from the class attribute.
|
||||
*
|
||||
* @param class-string<\Illuminate\Http\Resources\Json\JsonResource> $class
|
||||
* @return class-string<*>|null
|
||||
*/
|
||||
protected function resolveResourceFromAttribute(string $class): ?string
|
||||
{
|
||||
if (! class_exists($class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributes = (new ReflectionClass($class))->getAttributes(UseResource::class);
|
||||
|
||||
return $attributes !== []
|
||||
? $attributes[0]->newInstance()->class
|
||||
: null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the resource collection class from the class attribute.
|
||||
*
|
||||
* @param class-string<\Illuminate\Http\Resources\Json\ResourceCollection> $class
|
||||
* @return class-string<*>|null
|
||||
*/
|
||||
protected function resolveResourceCollectionFromAttribute(string $class): ?string
|
||||
{
|
||||
if (! class_exists($class)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$attributes = (new ReflectionClass($class))->getAttributes(UseResourceCollection::class);
|
||||
|
||||
return $attributes !== []
|
||||
? $attributes[0]->newInstance()->class
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -14,26 +14,31 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"illuminate/conditionable": "^10.0",
|
||||
"illuminate/contracts": "^10.0",
|
||||
"illuminate/macroable": "^10.0"
|
||||
"php": "^8.2",
|
||||
"illuminate/conditionable": "^12.0",
|
||||
"illuminate/contracts": "^12.0",
|
||||
"illuminate/macroable": "^12.0",
|
||||
"symfony/polyfill-php83": "^1.33",
|
||||
"symfony/polyfill-php84": "^1.33",
|
||||
"symfony/polyfill-php85": "^1.33"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Illuminate\\Support\\": ""
|
||||
},
|
||||
"files": [
|
||||
"functions.php",
|
||||
"helpers.php"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "10.x-dev"
|
||||
"dev-master": "12.x-dev"
|
||||
}
|
||||
},
|
||||
"suggest": {
|
||||
"symfony/var-dumper": "Required to use the dump method (^6.2)."
|
||||
"illuminate/http": "Required to convert collections to API resources (^12.0).",
|
||||
"symfony/var-dumper": "Required to use the dump method (^7.2)."
|
||||
},
|
||||
"config": {
|
||||
"sort-packages": true
|
||||
|
||||
+73
-6
@@ -13,7 +13,7 @@ if (! function_exists('collect')) {
|
||||
* @param \Illuminate\Contracts\Support\Arrayable<TKey, TValue>|iterable<TKey, TValue>|null $value
|
||||
* @return \Illuminate\Support\Collection<TKey, TValue>
|
||||
*/
|
||||
function collect($value = [])
|
||||
function collect($value = []): Collection
|
||||
{
|
||||
return new Collection($value);
|
||||
}
|
||||
@@ -34,6 +34,36 @@ if (! function_exists('data_fill')) {
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('data_has')) {
|
||||
/**
|
||||
* Determine if a key / property exists on an array or object using "dot" notation.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @param string|array|int|null $key
|
||||
* @return bool
|
||||
*/
|
||||
function data_has($target, $key): bool
|
||||
{
|
||||
if (is_null($key) || $key === []) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$key = is_array($key) ? $key : explode('.', $key);
|
||||
|
||||
foreach ($key as $segment) {
|
||||
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
|
||||
$target = $target[$segment];
|
||||
} elseif (is_object($target) && property_exists($target, $segment)) {
|
||||
$target = $target->{$segment};
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('data_get')) {
|
||||
/**
|
||||
* Get an item from an array or object using "dot" notation.
|
||||
@@ -74,6 +104,15 @@ if (! function_exists('data_get')) {
|
||||
return in_array('*', $key) ? Arr::collapse($result) : $result;
|
||||
}
|
||||
|
||||
$segment = match ($segment) {
|
||||
'\*' => '*',
|
||||
'\{first}' => '{first}',
|
||||
'{first}' => array_key_first(Arr::from($target)),
|
||||
'\{last}' => '{last}',
|
||||
'{last}' => array_key_last(Arr::from($target)),
|
||||
default => $segment,
|
||||
};
|
||||
|
||||
if (Arr::accessible($target) && Arr::exists($target, $segment)) {
|
||||
$target = $target[$segment];
|
||||
} elseif (is_object($target) && isset($target->{$segment})) {
|
||||
@@ -194,7 +233,7 @@ if (! function_exists('head')) {
|
||||
*/
|
||||
function head($array)
|
||||
{
|
||||
return reset($array);
|
||||
return empty($array) ? false : array_first($array);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,7 +246,7 @@ if (! function_exists('last')) {
|
||||
*/
|
||||
function last($array)
|
||||
{
|
||||
return end($array);
|
||||
return empty($array) ? false : array_last($array);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,12 +254,40 @@ if (! function_exists('value')) {
|
||||
/**
|
||||
* Return the default value of the given value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param mixed ...$args
|
||||
* @return mixed
|
||||
* @template TValue
|
||||
* @template TArgs
|
||||
*
|
||||
* @param TValue|\Closure(TArgs): TValue $value
|
||||
* @param TArgs ...$args
|
||||
* @return TValue
|
||||
*/
|
||||
function value($value, ...$args)
|
||||
{
|
||||
return $value instanceof Closure ? $value(...$args) : $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (! function_exists('when')) {
|
||||
/**
|
||||
* Return a value if the given condition is true.
|
||||
*
|
||||
* @template TValue
|
||||
* @template TArgs
|
||||
* @template TDefault
|
||||
*
|
||||
* @param mixed $condition
|
||||
* @param TValue|\Closure(TArgs): TValue $value
|
||||
* @param TDefault|\Closure(): TDefault $default
|
||||
* @return ($condition is true|positive-int|non-falsy-string|non-empty-array ? TValue : ($condition is callable ? TValue|TDefault : TDefault))
|
||||
*/
|
||||
function when($condition, $value, $default = null)
|
||||
{
|
||||
$condition = $condition instanceof Closure ? $condition() : $condition;
|
||||
|
||||
if ($condition) {
|
||||
return value($value, $condition);
|
||||
}
|
||||
|
||||
return value($default, $condition);
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,6 @@ class HigherOrderWhenProxy
|
||||
* Create a new proxy instance.
|
||||
*
|
||||
* @param mixed $target
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($target)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.0.2"
|
||||
"php": "^8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "10.x-dev"
|
||||
"dev-master": "12.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
||||
@@ -8,7 +8,7 @@ interface Authorizable
|
||||
* Determine if the entity has a given ability.
|
||||
*
|
||||
* @param iterable|string $abilities
|
||||
* @param array|mixed $arguments
|
||||
* @param mixed $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public function can($abilities, $arguments = []);
|
||||
|
||||
@@ -7,7 +7,7 @@ interface Gate
|
||||
/**
|
||||
* Determine if a given ability has been defined.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param \UnitEnum|string $ability
|
||||
* @return bool
|
||||
*/
|
||||
public function has($ability);
|
||||
@@ -15,7 +15,7 @@ interface Gate
|
||||
/**
|
||||
* Define a new ability.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param \UnitEnum|string $ability
|
||||
* @param callable|string $callback
|
||||
* @return $this
|
||||
*/
|
||||
@@ -29,7 +29,7 @@ interface Gate
|
||||
* @param array|null $abilities
|
||||
* @return $this
|
||||
*/
|
||||
public function resource($name, $class, array $abilities = null);
|
||||
public function resource($name, $class, ?array $abilities = null);
|
||||
|
||||
/**
|
||||
* Define a policy class for a given class type.
|
||||
@@ -59,8 +59,8 @@ interface Gate
|
||||
/**
|
||||
* Determine if all of the given abilities should be granted for the current user.
|
||||
*
|
||||
* @param iterable|string $ability
|
||||
* @param array|mixed $arguments
|
||||
* @param iterable|\UnitEnum|string $ability
|
||||
* @param mixed $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public function allows($ability, $arguments = []);
|
||||
@@ -68,8 +68,8 @@ interface Gate
|
||||
/**
|
||||
* Determine if any of the given abilities should be denied for the current user.
|
||||
*
|
||||
* @param iterable|string $ability
|
||||
* @param array|mixed $arguments
|
||||
* @param iterable|\UnitEnum|string $ability
|
||||
* @param mixed $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public function denies($ability, $arguments = []);
|
||||
@@ -77,8 +77,8 @@ interface Gate
|
||||
/**
|
||||
* Determine if all of the given abilities should be granted for the current user.
|
||||
*
|
||||
* @param iterable|string $abilities
|
||||
* @param array|mixed $arguments
|
||||
* @param iterable|\UnitEnum|string $abilities
|
||||
* @param mixed $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public function check($abilities, $arguments = []);
|
||||
@@ -86,8 +86,8 @@ interface Gate
|
||||
/**
|
||||
* Determine if any one of the given abilities should be granted for the current user.
|
||||
*
|
||||
* @param iterable|string $abilities
|
||||
* @param array|mixed $arguments
|
||||
* @param iterable|\UnitEnum|string $abilities
|
||||
* @param mixed $arguments
|
||||
* @return bool
|
||||
*/
|
||||
public function any($abilities, $arguments = []);
|
||||
@@ -95,8 +95,8 @@ interface Gate
|
||||
/**
|
||||
* Determine if the given ability should be granted for the current user.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param array|mixed $arguments
|
||||
* @param \UnitEnum|string $ability
|
||||
* @param mixed $arguments
|
||||
* @return \Illuminate\Auth\Access\Response
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
@@ -106,8 +106,8 @@ interface Gate
|
||||
/**
|
||||
* Inspect the user for the given ability.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param array|mixed $arguments
|
||||
* @param \UnitEnum|string $ability
|
||||
* @param mixed $arguments
|
||||
* @return \Illuminate\Auth\Access\Response
|
||||
*/
|
||||
public function inspect($ability, $arguments = []);
|
||||
@@ -116,7 +116,7 @@ interface Gate
|
||||
* Get the raw result from the authorization callback.
|
||||
*
|
||||
* @param string $ability
|
||||
* @param array|mixed $arguments
|
||||
* @param mixed $arguments
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Illuminate\Auth\Access\AuthorizationException
|
||||
|
||||
@@ -18,6 +18,13 @@ interface Authenticatable
|
||||
*/
|
||||
public function getAuthIdentifier();
|
||||
|
||||
/**
|
||||
* Get the name of the password attribute for the user.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAuthPasswordName();
|
||||
|
||||
/**
|
||||
* Get the password for the user.
|
||||
*
|
||||
|
||||
@@ -51,7 +51,7 @@ interface Guard
|
||||
* Set the current user.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
||||
* @return void
|
||||
* @return $this
|
||||
*/
|
||||
public function setUser(Authenticatable $user);
|
||||
}
|
||||
@@ -48,7 +48,7 @@ interface PasswordBroker
|
||||
* @param \Closure|null $callback
|
||||
* @return string
|
||||
*/
|
||||
public function sendResetLink(array $credentials, Closure $callback = null);
|
||||
public function sendResetLink(array $credentials, ?Closure $callback = null);
|
||||
|
||||
/**
|
||||
* Reset the password for the given token.
|
||||
|
||||
@@ -35,7 +35,7 @@ interface StatefulGuard extends Guard
|
||||
*
|
||||
* @param mixed $id
|
||||
* @param bool $remember
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|bool
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|false
|
||||
*/
|
||||
public function loginUsingId($id, $remember = false);
|
||||
|
||||
@@ -43,7 +43,7 @@ interface StatefulGuard extends Guard
|
||||
* Log the given user ID into the application without sessions or cookies.
|
||||
*
|
||||
* @param mixed $id
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|bool
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|false
|
||||
*/
|
||||
public function onceUsingId($id);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ interface UserProvider
|
||||
* @param string $token
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function retrieveByToken($identifier, $token);
|
||||
public function retrieveByToken($identifier, #[\SensitiveParameter] $token);
|
||||
|
||||
/**
|
||||
* Update the "remember me" token for the given user in storage.
|
||||
@@ -28,7 +28,7 @@ interface UserProvider
|
||||
* @param string $token
|
||||
* @return void
|
||||
*/
|
||||
public function updateRememberToken(Authenticatable $user, $token);
|
||||
public function updateRememberToken(Authenticatable $user, #[\SensitiveParameter] $token);
|
||||
|
||||
/**
|
||||
* Retrieve a user by the given credentials.
|
||||
@@ -36,7 +36,7 @@ interface UserProvider
|
||||
* @param array $credentials
|
||||
* @return \Illuminate\Contracts\Auth\Authenticatable|null
|
||||
*/
|
||||
public function retrieveByCredentials(array $credentials);
|
||||
public function retrieveByCredentials(#[\SensitiveParameter] array $credentials);
|
||||
|
||||
/**
|
||||
* Validate a user against the given credentials.
|
||||
@@ -45,5 +45,15 @@ interface UserProvider
|
||||
* @param array $credentials
|
||||
* @return bool
|
||||
*/
|
||||
public function validateCredentials(Authenticatable $user, array $credentials);
|
||||
public function validateCredentials(Authenticatable $user, #[\SensitiveParameter] array $credentials);
|
||||
|
||||
/**
|
||||
* Rehash the user's password if required and supported.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Auth\Authenticatable $user
|
||||
* @param array $credentials
|
||||
* @param bool $force
|
||||
* @return void
|
||||
*/
|
||||
public function rehashPasswordIfRequired(Authenticatable $user, #[\SensitiveParameter] array $credentials, bool $force = false);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Broadcasting;
|
||||
|
||||
interface ShouldRescue
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -44,7 +44,7 @@ interface Dispatcher
|
||||
* Retrieve the handler for a command.
|
||||
*
|
||||
* @param mixed $command
|
||||
* @return bool|mixed
|
||||
* @return mixed
|
||||
*/
|
||||
public function getCommandHandler($command);
|
||||
|
||||
|
||||
@@ -18,6 +18,8 @@ interface Lock
|
||||
* @param int $seconds
|
||||
* @param callable|null $callback
|
||||
* @return mixed
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Cache\LockTimeoutException
|
||||
*/
|
||||
public function block($seconds, $callback = null);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ interface Store
|
||||
/**
|
||||
* Retrieve an item from the cache by key.
|
||||
*
|
||||
* @param string|array $key
|
||||
* @param string $key
|
||||
* @return mixed
|
||||
*/
|
||||
public function get($key);
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Concurrency;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Support\Defer\DeferredCallback;
|
||||
|
||||
interface Driver
|
||||
{
|
||||
/**
|
||||
* Run the given tasks concurrently and return an array containing the results.
|
||||
*/
|
||||
public function run(Closure|array $tasks): array;
|
||||
|
||||
/**
|
||||
* Defer the execution of the given tasks.
|
||||
*/
|
||||
public function defer(Closure|array $tasks): DeferredCallback;
|
||||
}
|
||||
@@ -7,6 +7,16 @@ use Psr\Container\ContainerInterface;
|
||||
|
||||
interface Container extends ContainerInterface
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @template TClass of object
|
||||
*
|
||||
* @param string|class-string<TClass> $id
|
||||
* @return ($id is class-string<TClass> ? TClass : mixed)
|
||||
*/
|
||||
public function get(string $id);
|
||||
|
||||
/**
|
||||
* Determine if the given abstract type has been bound.
|
||||
*
|
||||
@@ -30,7 +40,7 @@ interface Container extends ContainerInterface
|
||||
* Assign a set of tags to a given binding.
|
||||
*
|
||||
* @param array|string $abstracts
|
||||
* @param array|mixed ...$tags
|
||||
* @param mixed ...$tags
|
||||
* @return void
|
||||
*/
|
||||
public function tag($abstracts, $tags);
|
||||
@@ -46,7 +56,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a binding with the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @param bool $shared
|
||||
* @return void
|
||||
@@ -65,7 +75,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a binding if it hasn't already been registered.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @param bool $shared
|
||||
* @return void
|
||||
@@ -75,7 +85,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a shared binding in the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @return void
|
||||
*/
|
||||
@@ -84,7 +94,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a shared binding if it hasn't already been registered.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @return void
|
||||
*/
|
||||
@@ -93,7 +103,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a scoped binding in the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @return void
|
||||
*/
|
||||
@@ -102,7 +112,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register a scoped binding if it hasn't already been registered.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string|null $concrete
|
||||
* @return void
|
||||
*/
|
||||
@@ -111,7 +121,7 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* "Extend" an abstract type in the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure $closure
|
||||
* @return void
|
||||
*
|
||||
@@ -122,9 +132,11 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Register an existing instance as shared in the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @param mixed $instance
|
||||
* @return mixed
|
||||
* @template TInstance of mixed
|
||||
*
|
||||
* @param \Closure|string $abstract
|
||||
* @param TInstance $instance
|
||||
* @return TInstance
|
||||
*/
|
||||
public function instance($abstract, $instance);
|
||||
|
||||
@@ -132,7 +144,7 @@ interface Container extends ContainerInterface
|
||||
* Add a contextual binding to the container.
|
||||
*
|
||||
* @param string $concrete
|
||||
* @param string $abstract
|
||||
* @param \Closure|string $abstract
|
||||
* @param \Closure|string $implementation
|
||||
* @return void
|
||||
*/
|
||||
@@ -149,8 +161,10 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Get a closure to resolve the given type from the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @return \Closure
|
||||
* @template TClass of object
|
||||
*
|
||||
* @param string|class-string<TClass> $abstract
|
||||
* @return ($abstract is class-string<TClass> ? \Closure(): TClass : \Closure(): mixed)
|
||||
*/
|
||||
public function factory($abstract);
|
||||
|
||||
@@ -164,9 +178,11 @@ interface Container extends ContainerInterface
|
||||
/**
|
||||
* Resolve the given type from the container.
|
||||
*
|
||||
* @param string $abstract
|
||||
* @template TClass of object
|
||||
*
|
||||
* @param string|class-string<TClass> $abstract
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @return ($abstract is class-string<TClass> ? TClass : mixed)
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Container\BindingResolutionException
|
||||
*/
|
||||
@@ -197,7 +213,7 @@ interface Container extends ContainerInterface
|
||||
* @param \Closure|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function beforeResolving($abstract, Closure $callback = null);
|
||||
public function beforeResolving($abstract, ?Closure $callback = null);
|
||||
|
||||
/**
|
||||
* Register a new resolving callback.
|
||||
@@ -206,7 +222,7 @@ interface Container extends ContainerInterface
|
||||
* @param \Closure|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function resolving($abstract, Closure $callback = null);
|
||||
public function resolving($abstract, ?Closure $callback = null);
|
||||
|
||||
/**
|
||||
* Register a new after resolving callback.
|
||||
@@ -215,5 +231,5 @@ interface Container extends ContainerInterface
|
||||
* @param \Closure|null $callback
|
||||
* @return void
|
||||
*/
|
||||
public function afterResolving($abstract, Closure $callback = null);
|
||||
public function afterResolving($abstract, ?Closure $callback = null);
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Container;
|
||||
|
||||
interface ContextualAttribute
|
||||
{
|
||||
//
|
||||
}
|
||||
+3
-3
@@ -16,7 +16,7 @@ interface ContextualBindingBuilder
|
||||
* Define the implementation for the contextual binding.
|
||||
*
|
||||
* @param \Closure|string|array $implementation
|
||||
* @return void
|
||||
* @return $this
|
||||
*/
|
||||
public function give($implementation);
|
||||
|
||||
@@ -24,7 +24,7 @@ interface ContextualBindingBuilder
|
||||
* Define tagged services to be used as the implementation for the contextual binding.
|
||||
*
|
||||
* @param string $tag
|
||||
* @return void
|
||||
* @return $this
|
||||
*/
|
||||
public function giveTagged($tag);
|
||||
|
||||
@@ -33,7 +33,7 @@ interface ContextualBindingBuilder
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $default
|
||||
* @return void
|
||||
* @return $this
|
||||
*/
|
||||
public function giveConfig($key, $default = null);
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Container;
|
||||
|
||||
/**
|
||||
* @method static newInstance(): static
|
||||
*/
|
||||
interface SelfBuilding
|
||||
{
|
||||
}
|
||||
@@ -21,7 +21,7 @@ interface Factory
|
||||
public function make($name, $value, $minutes = 0, $path = null, $domain = null, $secure = null, $httpOnly = true, $raw = false, $sameSite = null);
|
||||
|
||||
/**
|
||||
* Create a cookie that lasts "forever" (five years).
|
||||
* Create a cookie that lasts "forever" (400 days).
|
||||
*
|
||||
* @param string $name
|
||||
* @param string $value
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Database;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface ConcurrencyErrorDetector
|
||||
{
|
||||
/**
|
||||
* Determine if the given exception was caused by a concurrency error such as a deadlock or serialization failure.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return bool
|
||||
*/
|
||||
public function causedByConcurrencyError(Throwable $e): bool;
|
||||
}
|
||||
+1
-1
@@ -7,7 +7,7 @@ interface Castable
|
||||
/**
|
||||
* Get the name of the caster class to use when casting from / to this cast target.
|
||||
*
|
||||
* @param array $arguments
|
||||
* @param string[] $arguments
|
||||
* @return class-string<CastsAttributes|CastsInboundAttributes>|CastsAttributes|CastsInboundAttributes
|
||||
*/
|
||||
public static function castUsing(array $arguments);
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ interface CastsInboundAttributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function set(Model $model, string $key, mixed $value, array $attributes);
|
||||
|
||||
Vendored
+19
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Database\Eloquent;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
interface ComparesCastableAttributes
|
||||
{
|
||||
/**
|
||||
* Determine if the given values are equal.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $firstValue
|
||||
* @param mixed $secondValue
|
||||
* @return bool
|
||||
*/
|
||||
public function compare(Model $model, string $key, mixed $firstValue, mixed $secondValue);
|
||||
}
|
||||
Vendored
+1
-1
@@ -12,7 +12,7 @@ interface SerializesCastableAttributes
|
||||
* @param \Illuminate\Database\Eloquent\Model $model
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @param array $attributes
|
||||
* @param array<string, mixed> $attributes
|
||||
* @return mixed
|
||||
*/
|
||||
public function serialize(Model $model, string $key, mixed $value, array $attributes);
|
||||
|
||||
Vendored
+1
-1
@@ -9,7 +9,7 @@ interface SupportsPartialRelations
|
||||
*
|
||||
* @param string|null $column
|
||||
* @param string|\Closure|null $aggregate
|
||||
* @param string $relation
|
||||
* @param string|null $relation
|
||||
* @return $this
|
||||
*/
|
||||
public function ofMany($column = 'id', $aggregate = 'MAX', $relation = null);
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Database;
|
||||
|
||||
use Throwable;
|
||||
|
||||
interface LostConnectionDetector
|
||||
{
|
||||
/**
|
||||
* Determine if the given exception was caused by a lost connection.
|
||||
*
|
||||
* @param \Throwable $e
|
||||
* @return bool
|
||||
*/
|
||||
public function causedByLostConnection(Throwable $e): bool;
|
||||
}
|
||||
@@ -2,12 +2,19 @@
|
||||
|
||||
namespace Illuminate\Contracts\Database;
|
||||
|
||||
use Illuminate\Database\Eloquent\Relations\Relation;
|
||||
|
||||
class ModelIdentifier
|
||||
{
|
||||
/**
|
||||
* Use the Relation morphMap for a Model's name when serializing.
|
||||
*/
|
||||
protected static bool $useMorphMap = false;
|
||||
|
||||
/**
|
||||
* The class name of the model.
|
||||
*
|
||||
* @var string
|
||||
* @var class-string<\Illuminate\Database\Eloquent\Model>|string|null
|
||||
*/
|
||||
public $class;
|
||||
|
||||
@@ -37,23 +44,26 @@ class ModelIdentifier
|
||||
/**
|
||||
* The class name of the model collection.
|
||||
*
|
||||
* @var string|null
|
||||
* @var class-string<\Illuminate\Database\Eloquent\Collection>|null
|
||||
*/
|
||||
public $collectionClass;
|
||||
|
||||
/**
|
||||
* Create a new model identifier.
|
||||
*
|
||||
* @param string $class
|
||||
* @param class-string<\Illuminate\Database\Eloquent\Model>|null $class
|
||||
* @param mixed $id
|
||||
* @param array $relations
|
||||
* @param mixed $connection
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($class, $id, array $relations, $connection)
|
||||
{
|
||||
$this->id = $id;
|
||||
if ($class !== null && self::$useMorphMap) {
|
||||
$class = Relation::getMorphAlias($class);
|
||||
}
|
||||
|
||||
$this->class = $class;
|
||||
$this->id = $id;
|
||||
$this->relations = $relations;
|
||||
$this->connection = $connection;
|
||||
}
|
||||
@@ -61,7 +71,7 @@ class ModelIdentifier
|
||||
/**
|
||||
* Specify the collection class that should be used when serializing / restoring collections.
|
||||
*
|
||||
* @param string|null $collectionClass
|
||||
* @param class-string<\Illuminate\Database\Eloquent\Collection> $collectionClass
|
||||
* @return $this
|
||||
*/
|
||||
public function useCollectionClass(?string $collectionClass)
|
||||
@@ -70,4 +80,26 @@ class ModelIdentifier
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the fully-qualified class name of the Model.
|
||||
*
|
||||
* @return class-string<\Illuminate\Database\Eloquent\Model>|null
|
||||
*/
|
||||
public function getClass(): ?string
|
||||
{
|
||||
if (self::$useMorphMap && $this->class !== null) {
|
||||
return Relation::getMorphedModel($this->class) ?? $this->class;
|
||||
}
|
||||
|
||||
return $this->class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Indicate whether to use the relational morph-map when serializing Models.
|
||||
*/
|
||||
public static function useMorphMap(bool $useMorphMap = true): void
|
||||
{
|
||||
static::$useMorphMap = $useMorphMap;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Debug;
|
||||
|
||||
interface ShouldntReport
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -13,7 +13,7 @@ interface Encrypter
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
*/
|
||||
public function encrypt($value, $serialize = true);
|
||||
public function encrypt(#[\SensitiveParameter] $value, $serialize = true);
|
||||
|
||||
/**
|
||||
* Decrypt the given value.
|
||||
@@ -32,4 +32,18 @@ interface Encrypter
|
||||
* @return string
|
||||
*/
|
||||
public function getKey();
|
||||
|
||||
/**
|
||||
* Get the current encryption key and all previous encryption keys.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getAllKeys();
|
||||
|
||||
/**
|
||||
* Get the previous encryption keys.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getPreviousKeys();
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ interface StringEncrypter
|
||||
*
|
||||
* @throws \Illuminate\Contracts\Encryption\EncryptException
|
||||
*/
|
||||
public function encryptString($value);
|
||||
public function encryptString(#[\SensitiveParameter] $value);
|
||||
|
||||
/**
|
||||
* Decrypt the given string without unserialization.
|
||||
|
||||
@@ -7,7 +7,7 @@ interface Factory
|
||||
/**
|
||||
* Get a filesystem implementation.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param \UnitEnum|string|null $name
|
||||
* @return \Illuminate\Contracts\Filesystem\Filesystem
|
||||
*/
|
||||
public function disk($name = null);
|
||||
|
||||
@@ -18,6 +18,14 @@ interface Filesystem
|
||||
*/
|
||||
const VISIBILITY_PRIVATE = 'private';
|
||||
|
||||
/**
|
||||
* Get the full path to the file that exists at the given relative path.
|
||||
*
|
||||
* @param string $path
|
||||
* @return string
|
||||
*/
|
||||
public function path($path);
|
||||
|
||||
/**
|
||||
* Determine if a file exists.
|
||||
*
|
||||
@@ -52,6 +60,27 @@ interface Filesystem
|
||||
*/
|
||||
public function put($path, $contents, $options = []);
|
||||
|
||||
/**
|
||||
* Store the uploaded file on the disk.
|
||||
*
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $path
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|array|null $file
|
||||
* @param mixed $options
|
||||
* @return string|false
|
||||
*/
|
||||
public function putFile($path, $file = null, $options = []);
|
||||
|
||||
/**
|
||||
* Store the uploaded file on the disk with a given name.
|
||||
*
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string $path
|
||||
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile|string|array|null $file
|
||||
* @param string|array|null $name
|
||||
* @param mixed $options
|
||||
* @return string|false
|
||||
*/
|
||||
public function putFileAs($path, $file, $name = null, $options = []);
|
||||
|
||||
/**
|
||||
* Write a new file using a stream.
|
||||
*
|
||||
@@ -144,7 +173,7 @@ interface Filesystem
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @param bool $recursive
|
||||
* @return array
|
||||
* @return array<string>
|
||||
*/
|
||||
public function files($directory = null, $recursive = false);
|
||||
|
||||
@@ -152,7 +181,7 @@ interface Filesystem
|
||||
* Get all of the files from the given directory (recursive).
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @return array
|
||||
* @return array<string>
|
||||
*/
|
||||
public function allFiles($directory = null);
|
||||
|
||||
@@ -161,7 +190,7 @@ interface Filesystem
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @param bool $recursive
|
||||
* @return array
|
||||
* @return array<string>
|
||||
*/
|
||||
public function directories($directory = null, $recursive = false);
|
||||
|
||||
@@ -169,7 +198,7 @@ interface Filesystem
|
||||
* Get all (recursive) of the directories within a given directory.
|
||||
*
|
||||
* @param string|null $directory
|
||||
* @return array
|
||||
* @return array<string>
|
||||
*/
|
||||
public function allDirectories($directory = null);
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ interface Hasher
|
||||
* @param array $options
|
||||
* @return string
|
||||
*/
|
||||
public function make($value, array $options = []);
|
||||
public function make(#[\SensitiveParameter] $value, array $options = []);
|
||||
|
||||
/**
|
||||
* Check the given plain value against a hash.
|
||||
@@ -29,7 +29,7 @@ interface Hasher
|
||||
* @param array $options
|
||||
* @return bool
|
||||
*/
|
||||
public function check($value, $hashedValue, array $options = []);
|
||||
public function check(#[\SensitiveParameter] $value, $hashedValue, array $options = []);
|
||||
|
||||
/**
|
||||
* Check if the given hash has been hashed using the given options.
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\JsonSchema;
|
||||
|
||||
use Closure;
|
||||
|
||||
interface JsonSchema
|
||||
{
|
||||
/**
|
||||
* Create a new object schema instance.
|
||||
*
|
||||
* @param (Closure(JsonSchema): array<string, \Illuminate\JsonSchema\Types\Type>)|array<string, \Illuminate\JsonSchema\Types\Type> $properties
|
||||
* @return \Illuminate\JsonSchema\Types\ObjectType
|
||||
*/
|
||||
public function object(Closure|array $properties = []);
|
||||
|
||||
/**
|
||||
* Create a new array property instance.
|
||||
*
|
||||
* @return \Illuminate\JsonSchema\Types\ArrayType
|
||||
*/
|
||||
public function array();
|
||||
|
||||
/**
|
||||
* Create a new string property instance.
|
||||
*
|
||||
* @return \Illuminate\JsonSchema\Types\StringType
|
||||
*/
|
||||
public function string();
|
||||
|
||||
/**
|
||||
* Create a new integer property instance.
|
||||
*
|
||||
* @return \Illuminate\JsonSchema\Types\IntegerType
|
||||
*/
|
||||
public function integer();
|
||||
|
||||
/**
|
||||
* Create a new number property instance.
|
||||
*
|
||||
* @return \Illuminate\JsonSchema\Types\NumberType
|
||||
*/
|
||||
public function number();
|
||||
|
||||
/**
|
||||
* Create a new boolean property instance.
|
||||
*
|
||||
* @return \Illuminate\JsonSchema\Types\BooleanType
|
||||
*/
|
||||
public function boolean();
|
||||
|
||||
/**
|
||||
* Create a new multi-type union instance.
|
||||
*
|
||||
* @param array<int, string> $types
|
||||
* @return \Illuminate\JsonSchema\Types\UnionType
|
||||
*/
|
||||
public function union(array $types);
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Log;
|
||||
|
||||
use Monolog\Processor\ProcessorInterface;
|
||||
|
||||
interface ContextLogProcessor extends ProcessorInterface
|
||||
{
|
||||
}
|
||||
@@ -38,4 +38,14 @@ interface Mailer
|
||||
* @return \Illuminate\Mail\SentMessage|null
|
||||
*/
|
||||
public function send($view, array $data = [], $callback = null);
|
||||
|
||||
/**
|
||||
* Send a new message synchronously using a view.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Mail\Mailable|string|array $mailable
|
||||
* @param array $data
|
||||
* @param \Closure|string|null $callback
|
||||
* @return \Illuminate\Mail\SentMessage|null
|
||||
*/
|
||||
public function sendNow($mailable, array $data = [], $callback = null);
|
||||
}
|
||||
@@ -7,7 +7,7 @@ interface Dispatcher
|
||||
/**
|
||||
* Send the given notification to the given notifiable entities.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array|mixed $notifiables
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @return void
|
||||
*/
|
||||
@@ -16,9 +16,10 @@ interface Dispatcher
|
||||
/**
|
||||
* Send the given notification immediately.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array|mixed $notifiables
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @param array|null $channels
|
||||
* @return void
|
||||
*/
|
||||
public function sendNow($notifiables, $notification);
|
||||
public function sendNow($notifiables, $notification, ?array $channels = null);
|
||||
}
|
||||
@@ -15,7 +15,7 @@ interface Factory
|
||||
/**
|
||||
* Send the given notification to the given notifiable entities.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array|mixed $notifiables
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @return void
|
||||
*/
|
||||
@@ -24,7 +24,7 @@ interface Factory
|
||||
/**
|
||||
* Send the given notification immediately.
|
||||
*
|
||||
* @param \Illuminate\Support\Collection|array|mixed $notifiables
|
||||
* @param \Illuminate\Support\Collection|mixed $notifiables
|
||||
* @param mixed $notification
|
||||
* @return void
|
||||
*/
|
||||
|
||||
+15
-1
@@ -2,6 +2,13 @@
|
||||
|
||||
namespace Illuminate\Contracts\Pagination;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
*
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @method $this through(callable(TValue): mixed $callback)
|
||||
*/
|
||||
interface CursorPaginator
|
||||
{
|
||||
/**
|
||||
@@ -53,7 +60,7 @@ interface CursorPaginator
|
||||
/**
|
||||
* Get all of the items being paginated.
|
||||
*
|
||||
* @return array
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function items();
|
||||
|
||||
@@ -92,6 +99,13 @@ interface CursorPaginator
|
||||
*/
|
||||
public function hasPages();
|
||||
|
||||
/**
|
||||
* Determine if there are more items in the data source.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function hasMorePages();
|
||||
|
||||
/**
|
||||
* Get the base path for paginator generated URLs.
|
||||
*
|
||||
|
||||
+7
@@ -2,6 +2,13 @@
|
||||
|
||||
namespace Illuminate\Contracts\Pagination;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
*
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @extends Paginator<TKey, TValue>
|
||||
*/
|
||||
interface LengthAwarePaginator extends Paginator
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -2,6 +2,13 @@
|
||||
|
||||
namespace Illuminate\Contracts\Pagination;
|
||||
|
||||
/**
|
||||
* @template TKey of array-key
|
||||
*
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @method $this through(callable(TValue): mixed $callback)
|
||||
*/
|
||||
interface Paginator
|
||||
{
|
||||
/**
|
||||
@@ -29,6 +36,13 @@ interface Paginator
|
||||
*/
|
||||
public function fragment($fragment = null);
|
||||
|
||||
/**
|
||||
* Add all current query string values to the paginator.
|
||||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function withQueryString();
|
||||
|
||||
/**
|
||||
* The URL for the next page, or null.
|
||||
*
|
||||
@@ -46,7 +60,7 @@ interface Paginator
|
||||
/**
|
||||
* Get all of the items being paginated.
|
||||
*
|
||||
* @return array
|
||||
* @return array<TKey, TValue>
|
||||
*/
|
||||
public function items();
|
||||
|
||||
|
||||
@@ -7,23 +7,23 @@ use Closure;
|
||||
interface Pipeline
|
||||
{
|
||||
/**
|
||||
* Set the traveler object being sent on the pipeline.
|
||||
* Set the object being sent through the pipeline.
|
||||
*
|
||||
* @param mixed $traveler
|
||||
* @param mixed $passable
|
||||
* @return $this
|
||||
*/
|
||||
public function send($traveler);
|
||||
public function send($passable);
|
||||
|
||||
/**
|
||||
* Set the stops of the pipeline.
|
||||
* Set the array of pipes.
|
||||
*
|
||||
* @param dynamic|array $stops
|
||||
* @param mixed $pipes
|
||||
* @return $this
|
||||
*/
|
||||
public function through($stops);
|
||||
public function through($pipes);
|
||||
|
||||
/**
|
||||
* Set the method to call on the stops.
|
||||
* Set the method to call on the pipes.
|
||||
*
|
||||
* @param string $method
|
||||
* @return $this
|
||||
|
||||
@@ -58,7 +58,15 @@ interface InvokedProcess
|
||||
* Wait for the process to finish.
|
||||
*
|
||||
* @param callable|null $output
|
||||
* @return \Illuminate\Console\Process\ProcessResult
|
||||
* @return \Illuminate\Process\ProcessResult
|
||||
*/
|
||||
public function wait(callable $output = null);
|
||||
public function wait(?callable $output = null);
|
||||
|
||||
/**
|
||||
* Wait until the given callback returns true.
|
||||
*
|
||||
* @param callable|null $output
|
||||
* @return \Illuminate\Process\ProcessResult
|
||||
*/
|
||||
public function waitUntil(?callable $output = null);
|
||||
}
|
||||
@@ -39,6 +39,14 @@ interface ProcessResult
|
||||
*/
|
||||
public function output();
|
||||
|
||||
/**
|
||||
* Determine if the output contains the given string.
|
||||
*
|
||||
* @param string $output
|
||||
* @return bool
|
||||
*/
|
||||
public function seeInOutput(string $output);
|
||||
|
||||
/**
|
||||
* Get the error output of the process.
|
||||
*
|
||||
@@ -46,13 +54,21 @@ interface ProcessResult
|
||||
*/
|
||||
public function errorOutput();
|
||||
|
||||
/**
|
||||
* Determine if the error output contains the given string.
|
||||
*
|
||||
* @param string $output
|
||||
* @return bool
|
||||
*/
|
||||
public function seeInErrorOutput(string $output);
|
||||
|
||||
/**
|
||||
* Throw an exception if the process failed.
|
||||
*
|
||||
* @param callable|null $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function throw(callable $callback = null);
|
||||
public function throw(?callable $callback = null);
|
||||
|
||||
/**
|
||||
* Throw an exception if the process failed and the given condition is true.
|
||||
@@ -61,5 +77,5 @@ interface ProcessResult
|
||||
* @param callable|null $callback
|
||||
* @return $this
|
||||
*/
|
||||
public function throwIf(bool $condition, callable $callback = null);
|
||||
public function throwIf(bool $condition, ?callable $callback = null);
|
||||
}
|
||||
-1
@@ -11,7 +11,6 @@ class EntityNotFoundException extends InvalidArgumentException
|
||||
*
|
||||
* @param string $type
|
||||
* @param mixed $id
|
||||
* @return void
|
||||
*/
|
||||
public function __construct($type, $id)
|
||||
{
|
||||
|
||||
+10
-1
@@ -133,7 +133,7 @@ interface Job
|
||||
public function getName();
|
||||
|
||||
/**
|
||||
* Get the resolved name of the queued job class.
|
||||
* Get the display name of the queued job class.
|
||||
*
|
||||
* Resolves the name of "wrapped" jobs such as class-based handlers.
|
||||
*
|
||||
@@ -141,6 +141,15 @@ interface Job
|
||||
*/
|
||||
public function resolveName();
|
||||
|
||||
/**
|
||||
* Get the class of the queued job.
|
||||
*
|
||||
* Resolves the class of "wrapped" jobs such as class-based handlers.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function resolveQueuedJobClass();
|
||||
|
||||
/**
|
||||
* Get the name of the connection the job belongs to.
|
||||
*
|
||||
|
||||
@@ -2,6 +2,12 @@
|
||||
|
||||
namespace Illuminate\Contracts\Queue;
|
||||
|
||||
/**
|
||||
* @method int pendingSize(string|null $queue = null)
|
||||
* @method int delayedSize(string|null $queue = null)
|
||||
* @method int reservedSize(string|null $queue = null)
|
||||
* @method int|null creationTimeOfOldestPendingJob(string|null $queue = null)
|
||||
*/
|
||||
interface Queue
|
||||
{
|
||||
/**
|
||||
@@ -37,7 +43,6 @@ interface Queue
|
||||
*
|
||||
* @param string $payload
|
||||
* @param string|null $queue
|
||||
* @param array $options
|
||||
* @return mixed
|
||||
*/
|
||||
public function pushRaw($payload, $queue = null, array $options = []);
|
||||
|
||||
@@ -7,7 +7,7 @@ interface Factory
|
||||
/**
|
||||
* Get a Redis connection by name.
|
||||
*
|
||||
* @param string|null $name
|
||||
* @param \UnitEnum|string|null $name
|
||||
* @return \Illuminate\Redis\Connections\Connection
|
||||
*/
|
||||
public function connection($name = null);
|
||||
|
||||
@@ -67,6 +67,17 @@ interface ResponseFactory
|
||||
*/
|
||||
public function stream($callback, $status = 200, array $headers = []);
|
||||
|
||||
/**
|
||||
* Create a new streamed JSON response instance.
|
||||
*
|
||||
* @param array $data
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
* @param int $encodingOptions
|
||||
* @return \Symfony\Component\HttpFoundation\StreamedJsonResponse
|
||||
*/
|
||||
public function streamJson($data, $status = 200, $headers = [], $encodingOptions = 15);
|
||||
|
||||
/**
|
||||
* Create a new streamed response instance as a file download.
|
||||
*
|
||||
@@ -112,7 +123,7 @@ interface ResponseFactory
|
||||
/**
|
||||
* Create a new redirect response to a named route.
|
||||
*
|
||||
* @param string $route
|
||||
* @param \BackedEnum|string $route
|
||||
* @param mixed $parameters
|
||||
* @param int $status
|
||||
* @param array $headers
|
||||
|
||||
@@ -59,6 +59,41 @@ interface UrlGenerator
|
||||
*/
|
||||
public function route($name, $parameters = [], $absolute = true);
|
||||
|
||||
/**
|
||||
* Create a signed route URL for a named route.
|
||||
*
|
||||
* @param string $name
|
||||
* @param mixed $parameters
|
||||
* @param \DateTimeInterface|\DateInterval|int|null $expiration
|
||||
* @param bool $absolute
|
||||
* @return string
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
public function signedRoute($name, $parameters = [], $expiration = null, $absolute = true);
|
||||
|
||||
/**
|
||||
* Create a temporary signed route URL for a named route.
|
||||
*
|
||||
* @param string $name
|
||||
* @param \DateTimeInterface|\DateInterval|int $expiration
|
||||
* @param array $parameters
|
||||
* @param bool $absolute
|
||||
* @return string
|
||||
*/
|
||||
public function temporarySignedRoute($name, $expiration, $parameters = [], $absolute = true);
|
||||
|
||||
/**
|
||||
* Generate an absolute URL with the given query parameters.
|
||||
*
|
||||
* @param string $path
|
||||
* @param array $query
|
||||
* @param mixed $extra
|
||||
* @param bool|null $secure
|
||||
* @return string
|
||||
*/
|
||||
public function query($path, $query = [], $extra = [], $secure = null);
|
||||
|
||||
/**
|
||||
* Get the URL to a controller action.
|
||||
*
|
||||
|
||||
@@ -98,6 +98,15 @@ interface Session
|
||||
*/
|
||||
public function put($key, $value = null);
|
||||
|
||||
/**
|
||||
* Flash a key / value pair to the session.
|
||||
*
|
||||
* @param string $key
|
||||
* @param mixed $value
|
||||
* @return void
|
||||
*/
|
||||
public function flash(string $key, $value = true);
|
||||
|
||||
/**
|
||||
* Get the CSRF token value.
|
||||
*
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Support;
|
||||
|
||||
interface HasOnceHash
|
||||
{
|
||||
/**
|
||||
* Compute the hash that should be used to represent the object when given to a function using "once".
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function onceHash();
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Illuminate\Contracts\Validation;
|
||||
|
||||
interface CompilableRules
|
||||
{
|
||||
/**
|
||||
* Compile the object into usable rules.
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param mixed $data
|
||||
* @param mixed $context
|
||||
* @return \stdClass
|
||||
*/
|
||||
public function compile($attribute, $value, $data = null, $context = null);
|
||||
}
|
||||
@@ -14,7 +14,7 @@ interface InvokableRule
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @return void
|
||||
*/
|
||||
public function __invoke(string $attribute, mixed $value, Closure $fail);
|
||||
|
||||
@@ -11,7 +11,7 @@ interface ValidationRule
|
||||
*
|
||||
* @param string $attribute
|
||||
* @param mixed $value
|
||||
* @param \Closure(string): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @param \Closure(string, ?string=): \Illuminate\Translation\PotentiallyTranslatedString $fail
|
||||
* @return void
|
||||
*/
|
||||
public function validate(string $attribute, mixed $value, Closure $fail): void;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.1",
|
||||
"php": "^8.2",
|
||||
"psr/container": "^1.1.1|^2.0.1",
|
||||
"psr/simple-cache": "^1.0|^2.0|^3.0"
|
||||
},
|
||||
@@ -25,7 +25,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "10.x-dev"
|
||||
"dev-master": "12.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
||||
@@ -6,6 +6,8 @@ use BadMethodCallException;
|
||||
use Closure;
|
||||
use ReflectionClass;
|
||||
use ReflectionMethod;
|
||||
use RuntimeException;
|
||||
use Throwable;
|
||||
|
||||
trait Macroable
|
||||
{
|
||||
@@ -21,6 +23,9 @@ trait Macroable
|
||||
*
|
||||
* @param string $name
|
||||
* @param object|callable $macro
|
||||
*
|
||||
* @param-closure-this static $macro
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public static function macro($name, $macro)
|
||||
@@ -117,7 +122,11 @@ trait Macroable
|
||||
$macro = static::$macros[$method];
|
||||
|
||||
if ($macro instanceof Closure) {
|
||||
$macro = $macro->bindTo($this, static::class);
|
||||
try {
|
||||
$macro = $macro->bindTo($this, static::class) ?? throw new RuntimeException;
|
||||
} catch (Throwable) {
|
||||
$macro = $macro->bindTo(null, static::class);
|
||||
}
|
||||
}
|
||||
|
||||
return $macro(...$parameters);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
}
|
||||
],
|
||||
"require": {
|
||||
"php": "^8.1"
|
||||
"php": "^8.2"
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
@@ -23,7 +23,7 @@
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "10.x-dev"
|
||||
"dev-master": "12.x-dev"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
|
||||
Reference in new issue
Block a user