public function ArraySerializable::extract in Zircon Profile 8.0
Same name and namespace in other branches
- 8 vendor/zendframework/zend-hydrator/src/ArraySerializable.php \Zend\Hydrator\ArraySerializable::extract()
Extract values from the provided object
Extracts values via the object's getArrayCopy() method.
Parameters
object $object:
Return value
array
Throws
Exception\BadMethodCallException for an $object not implementing getArrayCopy()
Overrides ExtractionInterface::extract
File
- vendor/
zendframework/ zend-hydrator/ src/ ArraySerializable.php, line 23
Class
Namespace
Zend\HydratorCode
public function extract($object) {
if (!is_callable([
$object,
'getArrayCopy',
])) {
throw new Exception\BadMethodCallException(sprintf('%s expects the provided object to implement getArrayCopy()', __METHOD__));
}
$data = $object
->getArrayCopy();
$filter = $this
->getFilter();
foreach ($data as $name => $value) {
if (!$filter
->filter($name)) {
unset($data[$name]);
continue;
}
$extractedName = $this
->extractName($name, $object);
// replace the original key with extracted, if differ
if ($extractedName !== $name) {
unset($data[$name]);
$name = $extractedName;
}
$data[$name] = $this
->extractValue($name, $value, $object);
}
return $data;
}