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>
165 lines
4.1 KiB
PHP
165 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace Inertia;
|
|
|
|
use Illuminate\Contracts\Http\Kernel as KernelContract;
|
|
use Illuminate\Contracts\Support\Responsable;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Routing\Router;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
use Throwable;
|
|
|
|
class ExceptionResponse implements Responsable
|
|
{
|
|
protected ?string $component = null;
|
|
|
|
/** @var array<string, mixed> */
|
|
protected array $props = [];
|
|
|
|
protected bool $includeSharedData = false;
|
|
|
|
protected ?string $rootView = null;
|
|
|
|
/** @var class-string<Middleware>|null */
|
|
protected ?string $middlewareClass = null;
|
|
|
|
public function __construct(
|
|
public readonly Throwable $exception,
|
|
public readonly Request $request,
|
|
public readonly Response $response,
|
|
protected readonly Router $router,
|
|
protected readonly KernelContract $kernel,
|
|
) {}
|
|
|
|
/**
|
|
* @param array<string, mixed> $props
|
|
*/
|
|
public function render(string $component, array $props = []): static
|
|
{
|
|
$this->component = $component;
|
|
$this->props = $props;
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* @param class-string<Middleware> $middlewareClass
|
|
*/
|
|
public function usingMiddleware(string $middlewareClass): static
|
|
{
|
|
$this->middlewareClass = $middlewareClass;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function withSharedData(): static
|
|
{
|
|
$this->includeSharedData = true;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function rootView(string $rootView): static
|
|
{
|
|
$this->rootView = $rootView;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function statusCode(): int
|
|
{
|
|
return $this->response->getStatusCode();
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
*/
|
|
public function toResponse($request): Response
|
|
{
|
|
if ($this->component === null) {
|
|
return $this->response;
|
|
}
|
|
|
|
$middleware = $this->resolveMiddleware();
|
|
|
|
if ($middleware) {
|
|
Inertia::version(fn () => $middleware->version($this->request));
|
|
Inertia::setRootView($this->rootView ?? $middleware->rootView($this->request));
|
|
} elseif ($this->rootView) {
|
|
Inertia::setRootView($this->rootView);
|
|
}
|
|
|
|
if ($this->includeSharedData && $middleware) {
|
|
Inertia::share($middleware->share($this->request));
|
|
|
|
foreach ($middleware->shareOnce($this->request) as $key => $value) {
|
|
if ($value instanceof OnceProp) {
|
|
Inertia::share($key, $value);
|
|
} else {
|
|
Inertia::shareOnce($key, $value);
|
|
}
|
|
}
|
|
}
|
|
|
|
return Inertia::render($this->component, $this->props)
|
|
->toResponse($this->request)
|
|
->setStatusCode($this->response->getStatusCode());
|
|
}
|
|
|
|
protected function resolveMiddleware(): ?Middleware
|
|
{
|
|
if ($this->middlewareClass) {
|
|
return app($this->middlewareClass);
|
|
}
|
|
|
|
$class = $this->resolveMiddlewareFromRoute() ?? $this->resolveMiddlewareFromKernel();
|
|
|
|
if ($class) {
|
|
return app($class);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return class-string<Middleware>|null
|
|
*/
|
|
protected function resolveMiddlewareFromRoute(): ?string
|
|
{
|
|
$route = $this->request->route();
|
|
|
|
if (! $route) {
|
|
return null;
|
|
}
|
|
|
|
foreach ($this->router->gatherRouteMiddleware($route) as $middleware) {
|
|
if (! is_string($middleware)) {
|
|
continue;
|
|
}
|
|
|
|
$class = head(explode(':', $middleware));
|
|
|
|
if (is_a($class, Middleware::class, true)) {
|
|
return $class;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return class-string<Middleware>|null
|
|
*/
|
|
protected function resolveMiddlewareFromKernel(): ?string
|
|
{
|
|
foreach ($this->kernel->getMiddlewareGroups() as $group) {
|
|
foreach ($group as $middleware) {
|
|
if (is_string($middleware) && is_a($middleware, Middleware::class, true)) {
|
|
return $middleware;
|
|
}
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|