Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mops1k/request-object-resolver-bundle
This bundle can help you to deserialize incoming request parameters from symfomy http request object to your DTO objects. This is a better alternative for new symfony request DTO resolvers.
https://github.com/mops1k/request-object-resolver-bundle
bundle php symfony symfony-bundle
Last synced: 3 days ago
JSON representation
This bundle can help you to deserialize incoming request parameters from symfomy http request object to your DTO objects. This is a better alternative for new symfony request DTO resolvers.
- Host: GitHub
- URL: https://github.com/mops1k/request-object-resolver-bundle
- Owner: mops1k
- License: mit
- Created: 2022-03-03T08:03:35.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-23T22:31:32.000Z (11 months ago)
- Last Synced: 2024-11-02T11:30:08.338Z (14 days ago)
- Topics: bundle, php, symfony, symfony-bundle
- Language: PHP
- Homepage:
- Size: 87.9 KB
- Stars: 9
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: License
Awesome Lists containing this project
README
# RequestObjectResolverBundle
This bundle can help you to deserialize incoming request parameters from symfomy http request object to your DTO objects.Deserialized objects are validated via [symfony/validator](https://symfony.com/doc/current/validation.html), so when using such objects in
controllers, we can be sure that the data format and their set in the object are correct and ready for further processing.Bundle can deserialize:
- route parameters (attribute `RequestObjectResolverBundle\Attribute\Path`)
- query parameters (attribute `RequestObjectResolverBundle\Attribute\Query`)
- content body (supports all symfony serializer formats) (attribute `RequestObjectResolverBundle\Attribute\Content`)
- form parameters (attribute `RequestObjectResolverBundle\Attribute\Form`)
- uploaded files (attribute `RequestObjectResolverBundle\Attribute\Form`)## Install
```bash
composer require mops1k/request-object-resolver-bundle
```## Use
Example:```php
$exampleRequest->id,
'name' => $exampleRequest->name,
]);
}
}
```## Map field to another name
Whole library attributes have a map parameter. With this parameter you can map from one field name to another.Example:
```php
'title']), Path] ExampleRequest $exampleRequest): JsonResponse
{
// some logic with $exampleRequest
return new JsonResponse([
'id' => $exampleRequest->id,
'title' => $exampleRequest->name,
]);
}
}
```## Skip dto validation
If your logic does not need automatic validation of the request object for some reason, then you can disable it
with `RequestObjectResolverBundle\Attribute\SkipValidation` attribute.Example:
```php
$exampleRequest->id,
'name' => $exampleRequest->name,
]);
}
}
```## Validation groups
If you want to use validation groups, then use attribute `\RequestObjectResolverBundle\Attribute\ValidationGroups`.Example:
```php
$exampleRequest->id,
'name' => $exampleRequest->name,
]);
}
}
```## Serialization context
If you want to add some serialization context, then in attributes you can set `serializationContext` property.Example:
```php
$exampleRequest->id,
'name' => $exampleRequest->name, // will throw error as uninitialized property
]);
}
}
```If you want to set context to all request parts which you want to deserialize to object,
use `\RequestObjectResolverBundle\Attribute\SerializerContext` attribute.```php
$exampleRequest->id,
'name' => $exampleRequest->name, // will throw error as uninitialized property
]);
}
}
```## Overriding values with request parts combination
These are table of request parts priority overriding (if have same key name):Request part|Priority (lower value = higher priority)
------------|----------------------------------------
Query|30
Path|20
Form|10
Content|0Example. If you handle `Path`, `Query` and `Content` in same object and all of them have same field (id for example),
then resulting field value will be from `Form` request part.