mirror of
https://github.com/mailcow/mailcow-dockerized.git
synced 2026-10-29 20:53:30 +00:00
[Web] Update composer libraries
This commit is contained in:
1297 files changed
+71585
-24460
No files matched your search
+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)
|
||||
|
||||
Reference in new issue
Block a user