Aggiornato Composer

This commit is contained in:
Paolo A
2024-05-17 12:24:19 +00:00
parent 4ac62108b5
commit ec201d75b2
2238 changed files with 38684 additions and 59785 deletions

View File

@@ -11,6 +11,9 @@
namespace Carbon\Traits;
use Carbon\CarbonInterface;
use Carbon\CarbonInterval;
use Carbon\CarbonPeriod;
use Closure;
use Generator;
use ReflectionClass;
@@ -99,12 +102,13 @@ trait Mixin
{
$context = eval(self::getAnonymousClassCodeForTrait($trait));
$className = \get_class($context);
$baseClass = static::class;
foreach (self::getMixableMethods($context) as $name) {
$closureBase = Closure::fromCallable([$context, $name]);
static::macro($name, function () use ($closureBase, $className) {
/** @phpstan-ignore-next-line */
static::macro($name, function (...$parameters) use ($closureBase, $className, $baseClass) {
$downContext = isset($this) ? ($this) : new $baseClass();
$context = isset($this) ? $this->cast($className) : new $className();
try {
@@ -117,7 +121,48 @@ trait Mixin
// in case of errors not converted into exceptions
$closure = $closure ?: $closureBase;
return $closure(...\func_get_args());
$result = $closure(...$parameters);
if (!($result instanceof $className)) {
return $result;
}
if ($downContext instanceof CarbonInterface && $result instanceof CarbonInterface) {
if ($context !== $result) {
$downContext = $downContext->copy();
}
return $downContext
->setTimezone($result->getTimezone())
->modify($result->format('Y-m-d H:i:s.u'))
->settings($result->getSettings());
}
if ($downContext instanceof CarbonInterval && $result instanceof CarbonInterval) {
if ($context !== $result) {
$downContext = $downContext->copy();
}
$downContext->copyProperties($result);
self::copyStep($downContext, $result);
self::copyNegativeUnits($downContext, $result);
return $downContext->settings($result->getSettings());
}
if ($downContext instanceof CarbonPeriod && $result instanceof CarbonPeriod) {
if ($context !== $result) {
$downContext = $downContext->copy();
}
return $downContext
->setDates($result->getStartDate(), $result->getEndDate())
->setRecurrences($result->getRecurrences())
->setOptions($result->getOptions())
->settings($result->getSettings());
}
return $result;
});
}
}
@@ -151,22 +196,12 @@ trait Mixin
protected static function bindMacroContext($context, callable $callable)
{
static::$macroContextStack[] = $context;
$exception = null;
$result = null;
try {
$result = $callable();
} catch (Throwable $throwable) {
$exception = $throwable;
return $callable();
} finally {
array_pop(static::$macroContextStack);
}
array_pop(static::$macroContextStack);
if ($exception) {
throw $exception;
}
return $result;
}
/**