zelenin/hydrator

Object hydrator

0.0.2 2017-06-22 13:30 UTC

This package is not auto-updated.

Last update: 2024-11-10 03:46:25 UTC


README

Installation

Composer

The preferred way to install this extension is through Composer.

Either run

php composer.phar require zelenin/hydrator "~0.0.1"

or add

"zelenin/hydrator": "~0.0.1"

to the require section of your composer.json

Usage

Example

$entity = new Entity(5, 'Title');

$hydrator = new StrategyHydrator(new ReflectionStrategy(), new RawNamingStrategy());

$data = $hydrator->extract($entity);
// $data = ['id' => 5, 'name' => 'Title']

$data = ['id' => 10, 'name' => 'New title'];

$newEntity = $hydrator->hydrate($entity, $data);
// $newEntity->getId() = 10, $newEntity->getName() = 'New title'

Author

Aleksandr Zelenin, e-mail: aleksandr@zelenin.me