This commit is contained in:
2023-12-03 01:26:55 +08:00
parent b7687f8a79
commit 6b66be1499
3 changed files with 24 additions and 3 deletions
+20
View File
@@ -545,4 +545,24 @@ class ConstrictRequest extends Message implements RequestInterface, ServerReques
}
return $size;
}
/**
* @param Request $request
* @return static
*/
public static function builder(Request $request): static
{
$static = (new static())->withUri(new Uri($request));
$static->withHeaders($request->header ?? []);
$static->withProtocolVersion($request->server['server_protocol']);
$static->withCookieParams($request->cookie ?? []);
$static->withServerParams($request->server);
$static->withQueryParams($request->get ?? []);
$static->withBody(new Stream($request->getContent()));
$static->withParsedBody($request);
$static->withUploadedFiles($request->files ?? []);
$static->withMethod($request->getMethod());
return $static;
}
}
-2
View File
@@ -44,7 +44,6 @@ class Handler implements RequestHandlerInterface
* @param ReflectionNamedType|null $reflectionType
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function __construct(public array|Closure $handler, public array $parameter, public ?ReflectionNamedType $reflectionType)
{
@@ -77,7 +76,6 @@ class Handler implements RequestHandlerInterface
* @return void
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function setRequestMethod(string $method): void
{
+4 -1
View File
@@ -15,6 +15,7 @@ use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
use ReflectionMethod;
use Throwable;
use Traversable;
use Kiri\Router\Base\Middleware;
@@ -78,13 +79,15 @@ class RouterCollector implements \ArrayAccess, \IteratorAggregate
/**
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
* @throws ReflectionException
*/
public function __construct()
{
$found = di(NotFoundController::class);
$reflection = new \ReflectionMethod($found, 'fail');
$reflection = new ReflectionMethod($found, 'fail');
$this->found = new Handler([$found, 'fail'], [], $reflection->getReturnType());
}