Download the PHP package salamov/dto-hydrator without Composer
On this page you can find all versions of the php package salamov/dto-hydrator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download salamov/dto-hydrator
More information about salamov/dto-hydrator
Files in salamov/dto-hydrator
Package dto-hydrator
Short Description Dynamic Hydration For Dto's Transformers in API Platform
License MIT
Informations about the package dto-hydrator
Description
Dynamic Hydration for DTO's used by Transformers in API Platform .
Install
composer require salamov/dto-hydrator
Usage
While using API Platform , using custom DTO's (defining custom input/output in the @ApiResource
) requires you to deal with custom
transformers specially when your DTO represents an Entity .
-
When using an input transformer i.e : after the request body is denormalized into a DTO , you should dehydrate the DTO i.e transform it to an entity in order to be persisted .
-
When using an output transformer i.e : after the entity is retrieved and waiting to be normalized , you should hydrate the DTO i.e transform the entity into a DTO in order to be displayed .
-
The embedded objects inside the Dto must be an
@ApiResource
in order to generate the swagger documentation - If the embedded objects defines
id
within the denormalized request body it will be referenced and the data will be updated , either it will be persisted as a newEntity
.
Example
Above we defined an OrderDto
for the Order
Entity with two embedded objects
Customer
and Products
one is related to Order
by a ManyToOne
relations ship
and the other is related to Order
by a OneToMany
relationship.
GET Request
The above request will go first through your custom dataProvider (if you have one) retrieving
the Order
Entity to be transformed and normalized , if you defined an Ouput
for your @ApiResource
then you should define a transformer your transformer would look like this :
PUT Request
The above request will be denormalized to your Input
class defined in the @ApiResource
then to your InputTransformer
in order to be transformed to an Entity
and persisted , so your InputTransformer
would look like this :
N.B : If your body/embedded body contains an id
it will be directly referenced to
the corresponding entity for that id
and the data will be updated , if not it will be created .
Security
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
License
The MIT License (MIT). Please see License File for more information.
All versions of dto-hydrator with dependencies
symfony/property-info Version ^4.0
symfony/serializer Version ^4.0
doctrine/common Version ^2.7
doctrine/orm Version ^2.4
symfony/http-foundation Version ^4.0
symfony/property-access Version ^4.0
symfony/framework-bundle Version 4.2.*
symfony/dependency-injection Version 4.2.*