This commit is contained in:
2024-12-16 16:29:35 +08:00
parent daa02a6408
commit dc561cec9b
7 changed files with 89 additions and 49 deletions
+13 -5
View File
@@ -9,7 +9,16 @@ use Psr\Http\Message\ResponseInterface;
class MixedFormat implements IFormat
{
/**
/**
* @param ResponseInterface $response
*/
public function __construct(public ResponseInterface $response)
{
}
/**
* @param mixed $result
* @return ResponseInterface
*/
@@ -18,14 +27,13 @@ class MixedFormat implements IFormat
if ($result instanceof ResponseInterface) {
return $result;
}
$response = Kiri::getDi()->get(ResponseInterface::class);
if (is_object($result)) {
return $response->withBody(new Stream('[object]'));
return $this->response->withBody(new Stream('[object]'));
}
if (is_array($result)) {
return $response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
} else {
return $response->withBody(new Stream((string)$result));
return $this->response->withBody(new Stream((string)$result));
}
}