-
Notifications
You must be signed in to change notification settings - Fork 0
Enhance request handling with query parameters and HTTP method access. #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace TinyBlocks\Http\Internal\Request; | ||
|
|
||
| use Psr\Http\Message\ServerRequestInterface; | ||
|
|
||
| final readonly class QueryParameters | ||
| { | ||
| private function __construct(private array $data) | ||
| { | ||
| } | ||
|
|
||
| public static function from(ServerRequestInterface $request): QueryParameters | ||
| { | ||
| return new QueryParameters(data: $request->getQueryParams()); | ||
| } | ||
|
|
||
| public function get(string $key): Attribute | ||
| { | ||
| $value = ($this->data[$key] ?? null); | ||
|
|
||
| return Attribute::from(value: $value); | ||
| } | ||
|
|
||
| public function toArray(): array | ||
| { | ||
| return $this->data; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,4 +23,9 @@ public function decode(): DecodedRequest | |
| { | ||
| return Decoder::from(request: $this->request)->decode(); | ||
| } | ||
|
|
||
| public function method(): Method | ||
| { | ||
| return Method::from(value: $this->request->getMethod()); | ||
gustavofreze marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
Comment on lines
+27
to
+30
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The json_decode on line 22 can return null if the JSON is invalid or a non-array value if the JSON doesn't represent an array. This would cause a type error when constructing Body, which expects an array parameter. Consider adding a check to ensure json_decode returns an array before passing it to the constructor, falling through to the empty array case otherwise.