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

@@ -1,5 +1,6 @@
<?php
use Carbon\CarbonInterval;
use Illuminate\Contracts\Support\DeferringDisplayableValue;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Model;
@@ -127,7 +128,7 @@ if (! function_exists('e')) {
}
if ($value instanceof Htmlable) {
return $value->toHtml();
return $value->toHtml() ?? '';
}
if ($value instanceof BackedEnum) {
@@ -232,7 +233,7 @@ if (! function_exists('laravel_cloud')) {
function laravel_cloud(): bool
{
return ($_ENV['LARAVEL_CLOUD'] ?? false) === '1' ||
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1';
($_SERVER['LARAVEL_CLOUD'] ?? false) === '1';
}
}
@@ -288,9 +289,7 @@ if (! function_exists('preg_replace_array')) {
function preg_replace_array($pattern, array $replacements, $subject): string
{
return preg_replace_callback($pattern, function () use (&$replacements) {
foreach ($replacements as $value) {
return array_shift($replacements);
}
return array_shift($replacements);
}, $subject);
}
}
@@ -303,7 +302,7 @@ if (! function_exists('retry')) {
*
* @param int|array<int, int> $times
* @param callable(int): TValue $callback
* @param int|\Closure(int, \Throwable): int $sleepMilliseconds
* @param CarbonInterval|int|\Closure(int, \Throwable): CarbonInterval|int $sleepMilliseconds
* @param (callable(\Throwable): bool)|null $when
* @return TValue
*
@@ -335,7 +334,11 @@ if (! function_exists('retry')) {
$sleepMilliseconds = $backoff[$attempts - 1] ?? $sleepMilliseconds;
if ($sleepMilliseconds) {
Sleep::usleep(value($sleepMilliseconds, $attempts, $e) * 1000);
$duration = value($sleepMilliseconds, $attempts, $e);
$duration instanceof CarbonInterval
? Sleep::usleep($duration->totalMicroseconds)
: Sleep::usleep($duration * 1000);
}
goto beginning;
@@ -398,11 +401,13 @@ if (! function_exists('throw_if')) {
* Throw the given exception if the given condition is true.
*
* @template TValue
* @template TParams of mixed
* @template TException of \Throwable
* @template TExceptionValue of TException|class-string<TException>|string
*
* @param TValue $condition
* @param TException|class-string<TException>|string $exception
* @param mixed ...$parameters
* @param Closure(TParams): TExceptionValue|TExceptionValue $exception
* @param TParams ...$parameters
* @return ($condition is true ? never : ($condition is non-empty-mixed ? never : TValue))
*
* @throws TException
@@ -410,6 +415,10 @@ if (! function_exists('throw_if')) {
function throw_if($condition, $exception = 'RuntimeException', ...$parameters)
{
if ($condition) {
if ($exception instanceof Closure) {
$exception = $exception(...$parameters);
}
if (is_string($exception) && class_exists($exception)) {
$exception = new $exception(...$parameters);
}
@@ -426,11 +435,13 @@ if (! function_exists('throw_unless')) {
* Throw the given exception unless the given condition is true.
*
* @template TValue
* @template TParams of mixed
* @template TException of \Throwable
* @template TExceptionValue of TException|class-string<TException>|string
*
* @param TValue $condition
* @param TException|class-string<TException>|string $exception
* @param mixed ...$parameters
* @param Closure(TParams): TExceptionValue|TExceptionValue $exception
* @param TParams ...$parameters
* @return ($condition is false ? never : ($condition is non-empty-mixed ? TValue : never))
*
* @throws TException