eee
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kiri\Router\Format;
|
||||
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Kiri\Router\Constrict\Stream;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
@@ -9,14 +10,20 @@ class ArrayFormat implements IFormat
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
#[Container(ResponseInterface::class)]
|
||||
public ResponseInterface $response;
|
||||
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
$result = json_encode($result, JSON_UNESCAPED_UNICODE);
|
||||
return \response()->withBody(new Stream($result));
|
||||
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Kiri\Router\Format;
|
||||
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Kiri\Router\Constrict\Stream;
|
||||
use Kiri\Router\ContentType;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
@@ -9,6 +10,13 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class MixedFormat implements IFormat
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
#[Container(ResponseInterface::class)]
|
||||
public ResponseInterface $response;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
@@ -17,12 +25,12 @@ class MixedFormat implements IFormat
|
||||
public function call(mixed $result): ResponseInterface
|
||||
{
|
||||
if (is_object($result)) {
|
||||
return \response()->withBody(new Stream('[object]'));
|
||||
return $this->response->withBody(new Stream('[object]'));
|
||||
}
|
||||
if (is_array($result)) {
|
||||
return \response()->withContentType(ContentType::JSON)->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
||||
return $this->response->withContentType(ContentType::JSON)->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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,12 +2,19 @@
|
||||
|
||||
namespace Kiri\Router\Format;
|
||||
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Kiri\Router\Constrict\Stream;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class OtherFormat implements IFormat
|
||||
{
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
#[Container(ResponseInterface::class)]
|
||||
public ResponseInterface $response;
|
||||
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
@@ -15,7 +22,7 @@ class OtherFormat implements IFormat
|
||||
*/
|
||||
public function call(mixed $result): ResponseInterface
|
||||
{
|
||||
return \response()->withBody(new Stream($result));
|
||||
return $this->response->withBody(new Stream($result));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,12 +2,21 @@
|
||||
|
||||
namespace Kiri\Router\Format;
|
||||
|
||||
use Kiri\Di\Inject\Container;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
class VoidFormat implements IFormat
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @var ResponseInterface
|
||||
*/
|
||||
#[Container(ResponseInterface::class)]
|
||||
public ResponseInterface $response;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return ResponseInterface
|
||||
@@ -15,7 +24,7 @@ class VoidFormat implements IFormat
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
// TODO: Implement call() method.
|
||||
return response();
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user