|null)> host => answer */ private static array $answers = []; /** * @param callable(Request): (PromiseInterface|array|null) $answer */ public static function script(string $host, callable $answer): void { self::$answers[$host] = $answer; } public static function reset(): void { self::$answers = []; } public static function answer(Request $request): ?PromiseInterface { $host = (string) parse_url($request->url(), PHP_URL_HOST); $answer = isset(self::$answers[$host]) ? (self::$answers[$host])($request) : null; return match (true) { $answer === null => null, $answer instanceof PromiseInterface => $answer, default => Http::response($answer), }; } }