From 6b66be149965fb7115650d5e1d8b66e35c308c5c Mon Sep 17 00:00:00 2001 From: whwyy Date: Sun, 3 Dec 2023 01:26:55 +0800 Subject: [PATCH] eee --- src/Constrict/ConstrictRequest.php | 20 ++++++++++++++++++++ src/Handler.php | 2 -- src/RouterCollector.php | 5 ++++- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Constrict/ConstrictRequest.php b/src/Constrict/ConstrictRequest.php index 49e0c7e..d8bb12d 100644 --- a/src/Constrict/ConstrictRequest.php +++ b/src/Constrict/ConstrictRequest.php @@ -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; + } } diff --git a/src/Handler.php b/src/Handler.php index bc8a878..04d34fd 100644 --- a/src/Handler.php +++ b/src/Handler.php @@ -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 { diff --git a/src/RouterCollector.php b/src/RouterCollector.php index c000427..7a00828 100644 --- a/src/RouterCollector.php +++ b/src/RouterCollector.php @@ -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()); }