eee
This commit is contained in:
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Kiri\Router\Format;
|
||||||
|
|
||||||
|
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.
|
||||||
|
if ($result instanceof ResponseInterface) {
|
||||||
|
$result->getBody()->write('');
|
||||||
|
} else {
|
||||||
|
$result = response()->withBody(new Stream());
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
}
|
||||||
+7
-2
@@ -7,6 +7,7 @@ use Closure;
|
|||||||
use Kiri\Router\Format\ArrayFormat;
|
use Kiri\Router\Format\ArrayFormat;
|
||||||
use Kiri\Router\Format\IFormat;
|
use Kiri\Router\Format\IFormat;
|
||||||
use Kiri\Router\Format\MixedFormat;
|
use Kiri\Router\Format\MixedFormat;
|
||||||
|
use Kiri\Router\Format\NoBody;
|
||||||
use Kiri\Router\Format\OtherFormat;
|
use Kiri\Router\Format\OtherFormat;
|
||||||
use Kiri\Router\Format\ResponseFormat;
|
use Kiri\Router\Format\ResponseFormat;
|
||||||
use Kiri\Router\Format\VoidFormat;
|
use Kiri\Router\Format\VoidFormat;
|
||||||
@@ -36,13 +37,14 @@ class Handler implements RequestHandlerInterface
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array|Closure $handler
|
* @param array|Closure $handler
|
||||||
|
* @param string $method
|
||||||
* @param array $parameter
|
* @param array $parameter
|
||||||
* @param ReflectionNamedType|null $reflectionType
|
* @param ReflectionNamedType|null $reflectionType
|
||||||
* @throws ReflectionException
|
|
||||||
* @throws ContainerExceptionInterface
|
* @throws ContainerExceptionInterface
|
||||||
* @throws NotFoundExceptionInterface
|
* @throws NotFoundExceptionInterface
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
public function __construct(public array|Closure $handler, public array $parameter, public ?ReflectionNamedType $reflectionType)
|
public function __construct(public array|Closure $handler, string $method, public array $parameter, public ?ReflectionNamedType $reflectionType)
|
||||||
{
|
{
|
||||||
$this->container = \Kiri::getDi();
|
$this->container = \Kiri::getDi();
|
||||||
if ($this->reflectionType != null) {
|
if ($this->reflectionType != null) {
|
||||||
@@ -50,6 +52,9 @@ class Handler implements RequestHandlerInterface
|
|||||||
} else {
|
} else {
|
||||||
$this->format = $this->container->get(MixedFormat::class);
|
$this->format = $this->container->get(MixedFormat::class);
|
||||||
}
|
}
|
||||||
|
if ($method === 'HEAD') {
|
||||||
|
$this->format = $this->container->get(NoBody::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user