35 lines
941 B
PHP
35 lines
941 B
PHP
<?php
|
|
|
|
namespace Kiri\Router\Format;
|
|
|
|
use Kiri;
|
|
use Kiri\Router\Constrict\Stream;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
class NoBody implements IFormat
|
|
{
|
|
|
|
/**
|
|
* @param $result
|
|
* @return ResponseInterface
|
|
*/
|
|
public function call($result): ResponseInterface
|
|
{
|
|
// TODO: Implement call() method.
|
|
$response = Kiri::getDi()->get(ResponseInterface::class);
|
|
if (request()->getMethod() === 'HEAD') {
|
|
return $response->withBody(new Stream());
|
|
}
|
|
if ($result instanceof ResponseInterface) {
|
|
return $result;
|
|
}
|
|
if (is_object($result)) {
|
|
return $response->withBody(new Stream('[object]'));
|
|
}
|
|
if (is_array($result)) {
|
|
return $response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
|
} else {
|
|
return $response->withBody(new Stream((string)$result));
|
|
}
|
|
}
|
|
} |