Download the PHP package crtl/request-dto-resolver-bundle without Composer
On this page you can find all versions of the php package crtl/request-dto-resolver-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download crtl/request-dto-resolver-bundle
More information about crtl/request-dto-resolver-bundle
Files in crtl/request-dto-resolver-bundle
Package request-dto-resolver-bundle
Short Description Deserializes and validates requests into objects
License MIT
Informations about the package request-dto-resolver-bundle
crtl/request-dto-resolver-bundle
A Symfony bundle for predictable, type-safe instantiation and validation of request DTOs.
It removes boilerplate from controllers while staying close to Symfony’s native validation and argument resolving mechanisms.
Features
-
Automatic DTO Resolution
DTOs type-hinted in controller actions are instantiated and validated automatically. -
Native Symfony Validator Integration
Uses Symfony’sValidatorInterfacewithout custom validation layers. -
Nested DTO Support
Supports complex request payloads with nested DTOs for query, body, header, file and route parameters. -
Strict Typing Friendly
DTO properties can be strictly typed for better IDE support and safer refactoring. - Flexible Query Parameter Transformation
Query parameters can be transformed to scalar types or via custom callbacks.
Installation
`
Configuration
Register the bundle in your Symfony application:
Bundle Options
The bundle exposes two options under the crtl_request_dto_resolver key:
| Option | Type | Default | Description |
|---|---|---|---|
default_strict |
bool |
true |
Controls how property values are assigned during hydration. When true, values are assigned directly ($object->prop = $value), which enforces PHP's native type checks. When false, values are assigned via reflection, allowing implicit type coercion. |
default_null |
bool |
false |
When true, properties that are missing from the request are treated as if null was sent. For non-nullable properties this produces a type constraint violation; for nullable properties the value is skipped as usual. |
These serve as bundle-level defaults. Individual DTOs can override them via the #[RequestDto] attribute:
When the attribute parameter is omitted (or explicitly set to null), the bundle-level default is used.
Usage
Step 1: Define a Request DTO
Create a DTO class and annotate it with #[RequestDto].
Use parameter attributes to map request data to properties.
The attribute is required to identify which controller arguments should be resolved and validated.
1.1 Strictly typed DTO
Any type mismatches will trigger a constraint violation and thus a
RequestValidationExceptionis thrown.
1.2 Mixed typed DTO
1.3 Important notes about DTO hydration
-
Uninitialized properties
If a request does not contain data for a property, that property will remain uninitialized.
To guarantee initialization, either:- provide a default value, or
- add appropriate validation constraints (e.g.
NotNull,NotBlank).
-
Hydration from arrays
When a DTO is manually hydrated from an array usingRequestDtoFactory::fromArray(), the configuredAbstractParam::$nameis ignored.
In this case, the DTO’s property names are always used as the source keys. - Validation still runs in strict mode
Even if some properties cannot be assigned due to type mismatches in strict typing mode, the DTO is still fully validated using Symfony’s validator.
Any resulting violations will lead to aRequestValidationException.
1.4 Validation group sequences
All Symfony validation group sequence variants are supported.
Because request data can never be trusted, DTO properties may be uninitialized regardless of whether strict typing is used or not.
Missing or invalid input can prevent a property from being assigned during hydration.
When using validation group sequences, you must therefore ensure that properties are accessed safely by:
- checking initialization with
isset(), or - using reflection-based checks when necessary.
Failing to do so may lead to runtime errors before later validation groups are evaluated.
Step 2: Use the DTO in a Controller
Handling Validation Errors
On validation failure, a RequestValidationException is thrown.
The bundle registers a default exception subscriber (priority -32) that returns a
400 Bad RequestJSON response.
You can override this with your own listener:
License
This bundle is licensed under the MIT License. See the LICENSE file for details.
All versions of request-dto-resolver-bundle with dependencies
symfony/http-kernel Version ^7.2 | ^8.0
symfony/validator Version ^7.2 | ^8.0
symfony/dependency-injection Version ^7.2 | ^8.0
symfony/property-info Version ^7.2 | ^8.0
symfony/cache Version ^7.1 | ^8.0
symfony/framework-bundle Version ^7.1 | ^8.0
psr/log Version ^3.0
phpdocumentor/reflection-docblock Version ^5.6