didix16 / php-hydrator
A simple library that uses the hydration pattern to fill objects given different sources of data.
Installs: 7 199
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Requires
- php: >= 7.2
README
A simple library that uses the hydration pattern to fill objects given different sources of data.
Content
What is Data Hydration
Data hydration is the import of data into an object. When an object is waiting for data to fill it, this object is waiting to be hydrated. The source of that hydration can be a data lake or other data source. There are a number of data hydration methods to properly select and fill objects with the appropriate data
Installation
composer require didix16/php-hydrator
Usage
class MyModel { private $property1; private $property2; ... } // this is an hydrator based on PHP reflection $hydrator = new ReflectionHydrator(); $model = new MyModel(); $hydrator->hydrate([ 'property1' => 'value1', 'propery2' => 'value2' ], $model); //$model->getProperty1() === 'value1' //$model->getProperty2() === 'value2' $data = $hydrator->extract($model); // data = ['property1' => 'value1', 'property2' => 'value2']
class MyModel implements \ArrayAccess { protected $property1; protected $property2; // Implementation of ArrayAccess interface methods ... } // this is an hydrator based on object array serialization $hydrator = new ArraySerializableHydrator(); $model = new MyModel(); $hydrator->hydrate([ 'property1' => 'value1', 'propery2' => 'value2' ], $model); //$model->getProperty1() === 'value1' //$model->getProperty2() === 'value2' $data = $hydrator->extract($model); // data = ['property1' => 'value1', 'property2' => 'value2']
TODO
Implement ObjectPropertyHydrator
Implement ClassMethodsHydrator
For more info check: