33 lines
791 B
PHP
33 lines
791 B
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\Http;
|
|
|
|
/**
|
|
* Kontextobjekt, das durch die Middleware-Kette weitergegeben wird.
|
|
* Es enthält sowohl den ursprünglichen Request als auch eine optionale Response.
|
|
*/
|
|
final readonly class MiddlewareContext
|
|
{
|
|
public function __construct(
|
|
public Request $request,
|
|
public ?Response $response = null,
|
|
) {}
|
|
|
|
/**
|
|
* Erstellt einen neuen Kontext mit der gleichen Anfrage, aber einer anderen Antwort
|
|
*/
|
|
public function withResponse(Response $response): self
|
|
{
|
|
return new self($this->request, $response);
|
|
}
|
|
|
|
/**
|
|
* Prüft, ob bereits eine Response im Kontext vorhanden ist
|
|
*/
|
|
public function hasResponse(): bool
|
|
{
|
|
return $this->response !== null;
|
|
}
|
|
}
|