https://github.com/fesor/doctrine-custom-hydrators
Set of Doctrine Custom Hydrators
https://github.com/fesor/doctrine-custom-hydrators
doctrine hydrator
Last synced: 3 months ago
JSON representation
Set of Doctrine Custom Hydrators
- Host: GitHub
- URL: https://github.com/fesor/doctrine-custom-hydrators
- Owner: fesor
- Created: 2017-04-27T18:15:07.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-04-27T18:17:30.000Z (about 8 years ago)
- Last Synced: 2025-01-07T17:16:20.320Z (5 months ago)
- Topics: doctrine, hydrator
- Language: PHP
- Size: 10.7 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Set of Doctrine Custom Hydrators
====================================This repository contains custom hydrators wich may be useful in some ordinary cases.
## Usage
TBD
## Custom Array Hydrators
When you are dealing with read-only operations like "get list of products" for example, there is no much profit from
your entities. What you really want if just data model, your domain object's state represented in some form suitable
for view layer. Also you don't need this objects to be stored in Unif-or-work since they should not be modified by
request.Simpliest way to achieve our goal will be use of `ArrayHydrator` to get needed data. But there is some problems in case
if you are using embeddable objects. By default doctrine returns embeddable obects inlined into array:```php
$row = [
'id' => 42,
'name' => 'Some Product Name',
'price.amount' => '3999',
'price.currency' => 'USD',
];
```So we can't just throw this into `json_encode` or `render`. We need some kind of post-processing of the result.
`NormalizedArrayHydrator` is doint just this. It post process result of array hydrator and make this example looks like this:
```php
$row = [
'id' => 42,
'name' => 'Some Product Name',
'price' => [
'amount' => '3999',
'currency' => 'USD',
],
];
```So now we could use this data to build representation of it for client's needs.