andrewdanilov / hydrator
Class for fill private object attributes from array, and extract data from object
1.0.1
2020-04-08 21:14 UTC
Requires
- php: >=5.6.0
- ext-mbstring: *
This package is auto-updated.
Last update: 2025-03-11 15:16:00 UTC
README
Class for fill private object attributes from array, and extract data from object
Installation
The preferred way to install this extension is through composer.
Either run
composer require andrewdanilov/hydrator "~1.0.0"
or add
"andrewdanilov/hydrator": "~1.0.0"
to the require section of your composer.json
file.
Usage
Filling data array from object attributes:
$object = new ExampleObject(); $hydrator = new \andrewdanilov\hydrator\Hydrator(); $data = $hydrator->extract($object, ['id', 'name']);
Filling object with data:
$data = [ 'id' => $id, 'name' => $name, ]; $hydrator = new \andrewdanilov\hydrator\Hydrator(); $object = $hydrator->hydrate(ExampleObject::class, $data);
Filling existing object with data:
$object = new ExampleObject(); $data = [ 'id' => $id, 'name' => $name, ]; $hydrator = new \andrewdanilov\hydrator\Hydrator(); $object = $hydrator->hydrateInto($object, $data);