eee
This commit is contained in:
@@ -9,14 +9,24 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class ArrayFormat implements IFormat
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
return di(ResponseInterface::class)->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function __construct(public ResponseInterface $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+32
-23
@@ -9,27 +9,36 @@ 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));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function __construct(public ResponseInterface $response)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
// TODO: Implement call() method.
|
||||
if (request()->getMethod() === 'HEAD') {
|
||||
return $this->response->withBody(new Stream());
|
||||
}
|
||||
if ($result instanceof ResponseInterface) {
|
||||
return $result;
|
||||
}
|
||||
if (is_object($result)) {
|
||||
return $this->response->withBody(new Stream('[object]'));
|
||||
}
|
||||
if (is_array($result)) {
|
||||
return $this->response->withBody(new Stream(json_encode($result, JSON_UNESCAPED_UNICODE)));
|
||||
} else {
|
||||
return $this->response->withBody(new Stream((string)$result));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,18 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class OtherFormat implements IFormat
|
||||
{
|
||||
|
||||
/**
|
||||
|
||||
public function __construct(public ResponseInterface $response)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $result
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call(mixed $result): ResponseInterface
|
||||
{
|
||||
return di(ResponseInterface::class)->withBody(new Stream($result));
|
||||
return $this->response->withBody(new Stream($result));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -8,14 +8,23 @@ use Psr\Http\Message\ResponseInterface;
|
||||
class VoidFormat implements IFormat
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
// TODO: Implement call() method.
|
||||
return di(ResponseInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResponseInterface $response
|
||||
*/
|
||||
public function __construct(public ResponseInterface $response)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $result
|
||||
*
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function call($result): ResponseInterface
|
||||
{
|
||||
// TODO: Implement call() method.
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -49,7 +49,7 @@ class Handler implements RequestHandlerInterface
|
||||
*/
|
||||
public function setRequestMethod(string $method): void
|
||||
{
|
||||
if ($method == 'HEAD') {
|
||||
if ($method == 'HEAD' || $method == 'OPTIONS') {
|
||||
$this->format = Kiri::getDi()->get(NoBody::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ use Kiri\Router\Base\AbstractHandler;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\ServerRequestInterface;
|
||||
use Psr\Http\Server\RequestHandlerInterface;
|
||||
use ReflectionException;
|
||||
|
||||
class HttpRequestHandler extends AbstractHandler implements RequestHandlerInterface
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user