https://github.com/alaaattya/transform-unicorn
A universal data transformer/hyderator
https://github.com/alaaattya/transform-unicorn
Last synced: 9 months ago
JSON representation
A universal data transformer/hyderator
- Host: GitHub
- URL: https://github.com/alaaattya/transform-unicorn
- Owner: AlaaAttya
- Created: 2017-07-29T14:44:11.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2017-07-29T14:59:01.000Z (almost 9 years ago)
- Last Synced: 2025-01-29T14:46:10.977Z (over 1 year ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Universal transformer unicorn
=============================
This package is used to transform an array to it's related model and transform a model object to an array.
for example, if you have a `Person` model and you need to create a new object of that model with specific data
you might use the following snippet
```php
$transformer = new Transformer\BaseTransformStrategy();
$testArray = [
'name' => 'alaa',
'email' => 'alaa.attya91@gmail.com'
];
// hydrate array to get an object
$object = $transformer->hydrate($testArray, Person::class);
```
and if you need to transform that model object to array you might use the following snippet
```php
$transformer->transform($object)
```