Allow PHP-8.2 and up Compatibility instead of just PHP-8.4

This commit is contained in:
johnnyq
2026-06-12 17:06:10 -04:00
parent 2204bd52f4
commit d3a93652f3
220 changed files with 7198 additions and 2635 deletions

View File

@@ -33,6 +33,8 @@ use function Illuminate\Support\enum_value;
* @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
@@ -81,6 +83,8 @@ trait EnumeratesValues
'first',
'flatMap',
'groupBy',
'hasMany',
'hasSole',
'keyBy',
'last',
'map',
@@ -329,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.
*
@@ -340,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);
}
/**
@@ -961,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());
}