From 284d5bdbf9599a3c7a969f2319decee1c73db3ee Mon Sep 17 00:00:00 2001 From: xl Date: Tue, 7 Nov 2023 14:28:57 +0800 Subject: [PATCH] eee --- src/Format/MixedFormat.php | 4 +++- src/Handler.php | 22 +++++++++++++--------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/Format/MixedFormat.php b/src/Format/MixedFormat.php index 910892b..6026e91 100644 --- a/src/Format/MixedFormat.php +++ b/src/Format/MixedFormat.php @@ -17,13 +17,15 @@ class MixedFormat implements IFormat public ResponseInterface $response; - /** * @param mixed $result * @return ResponseInterface */ public function call(mixed $result): ResponseInterface { + if ($result instanceof ResponseInterface) { + return $result; + } if (is_object($result)) { return $this->response->withBody(new Stream('[object]')); } diff --git a/src/Handler.php b/src/Handler.php index 94f65b5..48824a0 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -28,18 +28,22 @@ class Handler implements RequestHandlerInterface /** * @param array|Closure $handler * @param array $parameter - * @param ReflectionNamedType $reflectionType + * @param ReflectionNamedType|null $reflectionType * @throws ReflectionException */ - public function __construct(public array|Closure $handler, public array $parameter, public ReflectionNamedType $reflectionType) + public function __construct(public array|Closure $handler, public array $parameter, public ?ReflectionNamedType $reflectionType) { - $type = match ($this->reflectionType->getName()) { - 'array' => ArrayFormat::class, - 'mixed', 'object' => MixedFormat::class, - 'int', 'string', 'bool' => OtherFormat::class, - 'void' => VoidFormat::class, - default => ResponseFormat::class - }; + if ($this->reflectionType == null) { + $type = MixedFormat::class; + } else { + $type = match ($this->reflectionType->getName()) { + 'array' => ArrayFormat::class, + 'mixed', 'object' => MixedFormat::class, + 'int', 'string', 'bool' => OtherFormat::class, + 'void' => VoidFormat::class, + default => ResponseFormat::class + }; + } $this->format = di($type); }