This commit is contained in:
xl
2023-11-07 14:28:57 +08:00
parent ada5ebfdbd
commit 284d5bdbf9
2 changed files with 16 additions and 10 deletions
+3 -1
View File
@@ -17,13 +17,15 @@ class MixedFormat implements IFormat
public ResponseInterface $response; public ResponseInterface $response;
/** /**
* @param mixed $result * @param mixed $result
* @return ResponseInterface * @return ResponseInterface
*/ */
public function call(mixed $result): ResponseInterface public function call(mixed $result): ResponseInterface
{ {
if ($result instanceof ResponseInterface) {
return $result;
}
if (is_object($result)) { if (is_object($result)) {
return $this->response->withBody(new Stream('[object]')); return $this->response->withBody(new Stream('[object]'));
} }
+6 -2
View File
@@ -28,11 +28,14 @@ class Handler implements RequestHandlerInterface
/** /**
* @param array|Closure $handler * @param array|Closure $handler
* @param array $parameter * @param array $parameter
* @param ReflectionNamedType $reflectionType * @param ReflectionNamedType|null $reflectionType
* @throws ReflectionException * @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)
{ {
if ($this->reflectionType == null) {
$type = MixedFormat::class;
} else {
$type = match ($this->reflectionType->getName()) { $type = match ($this->reflectionType->getName()) {
'array' => ArrayFormat::class, 'array' => ArrayFormat::class,
'mixed', 'object' => MixedFormat::class, 'mixed', 'object' => MixedFormat::class,
@@ -40,6 +43,7 @@ class Handler implements RequestHandlerInterface
'void' => VoidFormat::class, 'void' => VoidFormat::class,
default => ResponseFormat::class default => ResponseFormat::class
}; };
}
$this->format = di($type); $this->format = di($type);
} }