From 2e97b91c135eefe5b607025471f8dd593ecdd310 Mon Sep 17 00:00:00 2001 From: "as2252258@163.com" Date: Wed, 4 Aug 2021 02:19:17 +0800 Subject: [PATCH] modify --- HttpServer/Http/Response.php | 5 ++++- System/Application.php | 5 +++-- function.php | 4 ++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/HttpServer/Http/Response.php b/HttpServer/Http/Response.php index 6984973e..92d8bc93 100644 --- a/HttpServer/Http/Response.php +++ b/HttpServer/Http/Response.php @@ -157,8 +157,11 @@ class Response extends HttpService * @return bool * @throws Exception */ - public function getBuilder(mixed $data, SResponse $response): static + public function getBuilder(mixed $data, SResponse $response = null): static { + if ($response === null) { + return $this->setContent($data); + } $response->setStatusCode($this->statusCode); if (!isset($response->header['Content-Type'])) { $response->header('Content-Type', $this->getResponseFormat()); diff --git a/System/Application.php b/System/Application.php index 9b4bd918..9cbe10eb 100644 --- a/System/Application.php +++ b/System/Application.php @@ -144,10 +144,11 @@ class Application extends BaseApplication if (!($class instanceof Command)) { scan_directory(directory('app'), 'App'); } - response()->send($manager->execCommand($class)); + $data = response()->getBuilder($manager->execCommand($class)); } catch (\Throwable $exception) { - response()->send(logger()->exception($exception)); + $data = response()->getBuilder(logger()->exception($exception)); } finally { + print_r($data); Timer::clearAll(); } } diff --git a/function.php b/function.php index 0206f3fe..72e1c022 100644 --- a/function.php +++ b/function.php @@ -590,10 +590,10 @@ if (!function_exists('name')) { if (!function_exists('response')) { /** - * @return Response|stdClass + * @return Response * @throws */ - function response(): Response|stdClass + function response(): Response { if (!Context::hasContext(Response::class)){ return Context::setContext(Response::class, new Response());