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