kwizer/hydrator

1.0.0 2018-04-09 16:42 UTC

This package is not auto-updated.

Last update: 2024-04-23 18:37:19 UTC


README

Build Status

A simple hydrator without mapping.

Why

Hydrate an instance simply with a data source.

How

Instantiate the hydrator and call the hydrate method with the object to hydrate and the data source

class MyClass
{
    private $foo;
}

$myDatas = ['foo' => 'bar'];
$hydrator = new \Kwizer\Hydrator\Hydrator();
$myObject = $hydrator->hydrate(MyClass::class, $myDatas);

You can directly hydrate an object already instantiated.

$myObject = new MyClass();
$myObject = $hydrator->hydrate($myObject, $myDatas);

Or hydrate with an object source

$datas = new \stdClass();
$datas->foo = 'bar';
$myObject = $hydrator->hydrate(MyClass::class, $myDatas);

The hyrator uses the with methods and set methods first if presents, then directly the property, breaking accessibility if necessary.

Installation

composer require kwizer/hydrator