Skip to content

Commit

Permalink
input deserializer
Browse files Browse the repository at this point in the history
  • Loading branch information
mlebkowski committed Jan 28, 2025
1 parent 1b2aa46 commit b8762f5
Show file tree
Hide file tree
Showing 12 changed files with 880 additions and 4 deletions.
20 changes: 20 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,3 +264,23 @@ The output will be silenced except for the following situatios:

In the former case, the output will be written in realtime, and in the two
latter ones you can expect it writtein in bulk at the end.


## Input parsing

In order to simplify input parsing, you can use the Symfony Serializer component to
automatically denormalize parsed request body or get params to a data transfer object
of your choice. In your controller, simply mark one of the parameters with `#[Payload]`
attribute and typehint it with your desired class:

```php
public function __invoke(#[WonderNetwork\SlimKernel\Http\Serializer\Payload] MyDto $input) {}
```

If the serializer fails to denormalize the input, a HttpBadRequestException will be
thrown with a semi-helpful message attached. If you require custom serializer setup,
you can register your own instance using the following container key:

```
\WonderNetwork\SlimKernel\ServiceFactory\SlimServiceFactory::INPUT_DENORMALIZER
```
8 changes: 6 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@
"name": "wondernetwork/slim-kernel",
"type": "library",
"require": {
"php": "^7.4|^8.0",
"php": ">=8.3",
"ext-json": "*",
"slim/slim": "^4.14",
"slim/psr7": "^1.6",
"php-di/php-di": "^6.4",
"dusank/knapsack": "^10.0",
"php-di/slim-bridge": "^3.4",
"symfony/console": "^5.4",
"symfony/finder": "^5.4"
"symfony/finder": "^5.4",
"symfony/property-access": "^7.2",
"symfony/serializer": "^7.2",
"phpstan/phpdoc-parser": "^2.0",
"phpdocumentor/reflection-docblock": "^5.6"
},
"license": "MIT",
"autoload": {
Expand Down
Loading

0 comments on commit b8762f5

Please sign in to comment.