This commit is contained in:
xl
2024-08-29 17:01:08 +08:00
parent 337c52c744
commit c435af1156
15 changed files with 61 additions and 167 deletions
+5 -13
View File
@@ -2,22 +2,13 @@
namespace Kiri\Router\Format;
use Kiri\Di\Inject\Container;
use Kiri;
use Kiri\Router\Constrict\Stream;
use Kiri\Router\ContentType;
use Psr\Http\Message\ResponseInterface;
class MixedFormat implements IFormat
{
/**
* @var ResponseInterface
*/
#[Container(ResponseInterface::class)]
public ResponseInterface $response;
/**
* @param mixed $result
* @return ResponseInterface
@@ -27,13 +18,14 @@ class MixedFormat implements IFormat
if ($result instanceof ResponseInterface) {
return $result;
}
$response = Kiri::getDi()->get(ResponseInterface::class);
if (is_object($result)) {
return $this->response->withBody(new Stream('[object]'));
return $response->withBody(new Stream('[object]'));
}
if (is_array($result)) {
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
return $response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
} else {
return $this->response->withBody(new Stream((string)$result));
return $response->withBody(new Stream((string)$result));
}
}