Some checks failed
CI / PHP 8.3 / mariadb:10.6 (pull_request) Successful in 1m14s
CI / PHP 8.4 / mariadb:10.6 (pull_request) Successful in 1m12s
CI / PHP 8.4 / mariadb:11.4 (pull_request) Successful in 1m7s
CI / PHP 8.3 / mariadb:11.4 (pull_request) Successful in 1m19s
CI / PHP 8.3 / mysql:8.0 (pull_request) Successful in 1m32s
CI / PHP 8.4 / mysql:8.0 (pull_request) Successful in 1m22s
CI / PHP 8.4 / mysql:8.4 (pull_request) Successful in 1m32s
CI / PHP 8.3 / mysql:8.4 (pull_request) Successful in 1m35s
CI / Build-Artefakte aktuell (pull_request) Failing after 1m7s
- Laravel 13 mit Filament 5 (Admin), Inertia 3 + Vue 3 + Vuetify 4 (Material 3) - Anmeldung über Fortify (Login, Passwort vergessen/ändern), keine Selbstregistrierung - Profil mit Profilbild (WebP in festen Größen), Personenseiten, Header mit Avatar-Menü - Material-3-Farbschema aus der Primärfarbe, hell/dunkel/System pro Person - Basis-Branding (Portalname, Logo, Primärfarbe) im Admin unter „Erscheinungsbild“ - Benutzerverwaltung im Admin, Zugang vorläufig über is_admin - vendor/ (ohne Dev-Pakete) und Frontend-Build mitversioniert, Dev-Pakete in vendor-dev/ - PHPUnit-Tests gegen MySQL/MariaDB, Forgejo-CI-Matrix, Docker-Entwicklungsumgebung - VERSION, CHANGELOG.md und CONTRIBUTING.md mit Release-Ablauf Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
129 lines
3 KiB
PHP
129 lines
3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
/**
|
|
* This file is part of the Carbon package.
|
|
*
|
|
* (c) Brian Nesbitt <brian@nesbot.com>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
namespace Carbon;
|
|
|
|
use Closure;
|
|
use DateInterval;
|
|
use DatePeriod;
|
|
use DateTime;
|
|
use DateTimeInterface;
|
|
use DateTimeZone;
|
|
use ReflectionFunction;
|
|
use ReflectionNamedType;
|
|
use ReflectionType;
|
|
|
|
final class Callback
|
|
{
|
|
private ?ReflectionFunction $function;
|
|
|
|
private function __construct(private readonly Closure $closure)
|
|
{
|
|
}
|
|
|
|
public static function fromClosure(Closure $closure): self
|
|
{
|
|
return new self($closure);
|
|
}
|
|
|
|
public static function parameter(mixed $closure, mixed $value, string|int $index = 0): mixed
|
|
{
|
|
if ($closure instanceof Closure) {
|
|
return self::fromClosure($closure)->prepareParameter($value, $index);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
public function getReflectionFunction(): ReflectionFunction
|
|
{
|
|
return $this->function ??= new ReflectionFunction($this->closure);
|
|
}
|
|
|
|
public function prepareParameter(mixed $value, string|int $index = 0): mixed
|
|
{
|
|
$type = $this->getParameterType($index);
|
|
|
|
if (!($type instanceof ReflectionNamedType)) {
|
|
return $value;
|
|
}
|
|
|
|
$name = $type->getName();
|
|
|
|
if ($name === CarbonInterface::class) {
|
|
$name = $value instanceof DateTime ? Carbon::class : CarbonImmutable::class;
|
|
}
|
|
|
|
if (!class_exists($name) || is_a($value, $name)) {
|
|
return $value;
|
|
}
|
|
|
|
$class = $this->getPromotedClass($value);
|
|
|
|
if ($class && is_a($name, $class, true)) {
|
|
return $name::instance($value);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
public function call(mixed ...$arguments): mixed
|
|
{
|
|
foreach ($arguments as $index => &$value) {
|
|
if ($this->getPromotedClass($value)) {
|
|
$value = $this->prepareParameter($value, $index);
|
|
}
|
|
}
|
|
|
|
return ($this->closure)(...$arguments);
|
|
}
|
|
|
|
private function getParameterType(string|int $index): ?ReflectionType
|
|
{
|
|
$parameters = $this->getReflectionFunction()->getParameters();
|
|
|
|
if (\is_int($index)) {
|
|
return ($parameters[$index] ?? null)?->getType();
|
|
}
|
|
|
|
foreach ($parameters as $parameter) {
|
|
if ($parameter->getName() === $index) {
|
|
return $parameter->getType();
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/** @return class-string|null */
|
|
private function getPromotedClass(mixed $value): ?string
|
|
{
|
|
if ($value instanceof DateTimeInterface) {
|
|
return CarbonInterface::class;
|
|
}
|
|
|
|
if ($value instanceof DateInterval) {
|
|
return CarbonInterval::class;
|
|
}
|
|
|
|
if ($value instanceof DatePeriod) {
|
|
return CarbonPeriod::class;
|
|
}
|
|
|
|
if ($value instanceof DateTimeZone) {
|
|
return CarbonTimeZone::class;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|