eee
This commit is contained in:
@@ -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]'));
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-9
@@ -28,18 +28,22 @@ 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)
|
||||||
{
|
{
|
||||||
$type = match ($this->reflectionType->getName()) {
|
if ($this->reflectionType == null) {
|
||||||
'array' => ArrayFormat::class,
|
$type = MixedFormat::class;
|
||||||
'mixed', 'object' => MixedFormat::class,
|
} else {
|
||||||
'int', 'string', 'bool' => OtherFormat::class,
|
$type = match ($this->reflectionType->getName()) {
|
||||||
'void' => VoidFormat::class,
|
'array' => ArrayFormat::class,
|
||||||
default => ResponseFormat::class
|
'mixed', 'object' => MixedFormat::class,
|
||||||
};
|
'int', 'string', 'bool' => OtherFormat::class,
|
||||||
|
'void' => VoidFormat::class,
|
||||||
|
default => ResponseFormat::class
|
||||||
|
};
|
||||||
|
}
|
||||||
$this->format = di($type);
|
$this->format = di($type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user