Skip to content
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

input deserializer #7

Merged
merged 2 commits into from
Jan 28, 2025
Merged

input deserializer #7

merged 2 commits into from
Jan 28, 2025

Conversation

mlebkowski
Copy link
Member

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:

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

@mlebkowski mlebkowski merged commit 90f1f44 into main Jan 28, 2025
1 check passed
@mlebkowski mlebkowski deleted the feature/input-deserializer branch January 28, 2025 19:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant