public function ArraySerializable::hydrate in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/zendframework/zend-hydrator/src/ArraySerializable.php \Zend\Hydrator\ArraySerializable::hydrate()
Hydrate an object
Hydrates an object by passing $data to either its exchangeArray() or populate() method.
Parameters
array $data:
object $object:
Return value
object
Throws
Exception\BadMethodCallException for an $object not implementing exchangeArray() or populate()
Overrides HydrationInterface::hydrate
File
- vendor/
zendframework/ zend-hydrator/ src/ ArraySerializable.php, line 62
Class
Namespace
Zend\HydratorCode
public function hydrate(array $data, $object) {
$replacement = [];
foreach ($data as $key => $value) {
$name = $this
->hydrateName($key, $data);
$replacement[$name] = $this
->hydrateValue($name, $value, $data);
}
if (is_callable([
$object,
'exchangeArray',
])) {
$object
->exchangeArray($replacement);
}
elseif (is_callable([
$object,
'populate',
])) {
$object
->populate($replacement);
}
else {
throw new Exception\BadMethodCallException(sprintf('%s expects the provided object to implement exchangeArray() or populate()', __METHOD__));
}
return $object;
}