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