Hydrate an object from an array of properties.
$ composer install keven/hydrate
Hydrate a given object:
<?php
$obj = new stdClass;
\Keven\hydrate(array('foo' => 'bar'), $obj);
echo $obj->foo; // "bar"
Hydrate from $this
(you don't have to pass the object parameter):
<?php
$car = new Car(array(
'engine' => 'V8',
'color' => 'red',
'brand' => 'Chevrolet',
));
echo $car->getColor(); // "red"
class Car
{
private $engine, $color, $brand;
public function __construct($args)
{
hydrate($args);
}
public function getEngine()
{
return $this->engine;
}
public function getColor()
{
return $this->color;
}
public function getBrand()
{
return $this->brand;
}
}