An open API service indexing awesome lists of open source software.

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

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)
```