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
Symfony bundle for streamlined instantiation and validation of request DTOs.
Features
- Automatic DTO Handling:
Instantly creates and validates Data Transfer Objects (DTOs) fromRequest
data, that are type-hinted in controller actions. - Symfony Validator Integration:
Leverages Symfony's built-in validator to ensure data integrity and compliance with your validation rules. - Nested DTO Support:
Handles complex request structures by supporting nested DTOs for both query and body parameters, making it easier to manage hierarchical data.
Installation
Configuration
Register the bundle in your Symfony application. Add the following to your config/bundles.php
file:
Usage
Step 1: Create a DTO
Create a class to represent your request data.
Annotate the class with #[RequestDTO]
and use bellow attributes for properties to map request parameters.
IMPORTANT
Each property must accept the type?string
except properties that are request DTOs.
Otherwise PHP may throw TypeErrors at runtime because we cannot know that the request contains the valid data type before validation.By default, each parameter is resolved by its property name.
If property name does not match parameter name you can pass an optional string to the constructor of each*Param
attribute (seeAbstractParam::__construct
).Each DTO can define an optional constructor which accepts a
Request
object
Step 2: Use the DTO in a Controller
Inject the DTO into your controller action. The RequestValueResolver
will automatically instantiate and validate the DTO.
Step 3: Handle Validation Errors
When validation fails, a
Crtl\RequestDTOResolverBundle\Exception\RequestValidationException
is thrown.You can create an event listener or override the default exception handler and handle validation errors.
License
This bundle is licensed under the MIT License. See the LICENSE file for more details.
All versions of request-dto-resolver-bundle with dependencies
symfony/http-kernel Version ^7.1
symfony/validator Version ^7.1
psr/log Version ^3.0
symfony/dependency-injection Version ^7.1