Skip to content

Commit 90f1f44

Browse files
authored
Merge pull request #7 from WonderNetwork/feature/input-deserializer
input deserializer
2 parents 1b2aa46 + a4dda6b commit 90f1f44

13 files changed

+881
-5
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
build:
1010
strategy:
1111
matrix:
12-
php_version: ['7.4', '8.3']
12+
php_version: ['8.3']
1313
runs-on: ubuntu-latest
1414

1515
steps:

Readme.md

+20
Original file line numberDiff line numberDiff line change
@@ -264,3 +264,23 @@ The output will be silenced except for the following situatios:
264264

265265
In the former case, the output will be written in realtime, and in the two
266266
latter ones you can expect it writtein in bulk at the end.
267+
268+
269+
## Input parsing
270+
271+
In order to simplify input parsing, you can use the Symfony Serializer component to
272+
automatically denormalize parsed request body or get params to a data transfer object
273+
of your choice. In your controller, simply mark one of the parameters with `#[Payload]`
274+
attribute and typehint it with your desired class:
275+
276+
```php
277+
public function __invoke(#[WonderNetwork\SlimKernel\Http\Serializer\Payload] MyDto $input) {}
278+
```
279+
280+
If the serializer fails to denormalize the input, a HttpBadRequestException will be
281+
thrown with a semi-helpful message attached. If you require custom serializer setup,
282+
you can register your own instance using the following container key:
283+
284+
```
285+
\WonderNetwork\SlimKernel\ServiceFactory\SlimServiceFactory::INPUT_DENORMALIZER
286+
```

composer.json

+6-2
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,19 @@
22
"name": "wondernetwork/slim-kernel",
33
"type": "library",
44
"require": {
5-
"php": "^7.4|^8.0",
5+
"php": ">=8.3",
66
"ext-json": "*",
77
"slim/slim": "^4.14",
88
"slim/psr7": "^1.6",
99
"php-di/php-di": "^6.4",
1010
"dusank/knapsack": "^10.0",
1111
"php-di/slim-bridge": "^3.4",
1212
"symfony/console": "^5.4",
13-
"symfony/finder": "^5.4"
13+
"symfony/finder": "^5.4",
14+
"symfony/property-access": "^7.2",
15+
"symfony/serializer": "^7.2",
16+
"phpstan/phpdoc-parser": "^2.0",
17+
"phpdocumentor/reflection-docblock": "^5.6"
1418
},
1519
"license": "MIT",
1620
"autoload": {

0 commit comments

Comments
 (0)