Files
kiri-router/src/Format/MixedFormat.php
T

30 lines
711 B
PHP
Raw Normal View History

2023-10-17 14:50:46 +08:00
<?php
namespace Kiri\Router\Format;
use Kiri\Router\Constrict\Stream;
use Kiri\Router\ContentType;
use Psr\Http\Message\ResponseInterface;
class MixedFormat implements IFormat
{
/**
* @param mixed $result
* @return ResponseInterface
*/
public function call(mixed $result): ResponseInterface
{
if (is_object($result)) {
return \response()->withBody(new Stream('[object]'));
}
if (is_array($result)) {
return \response()->withContentType(ContentType::JSON)->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
} else {
2023-10-17 17:01:18 +08:00
return \response()->withBody(new Stream((string)$result));
2023-10-17 14:50:46 +08:00
}
}
}