keven / hydrate
Hydrate an object from an array of properties.
Installs: 6 850
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/keven/hydrate
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: >=4
README
Hydrate an object from an array of properties.
Install
$ composer install keven/hydrate
Usage
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;
}
}