protected function entityToArray(IEntity $entity)
{
$return = [];
$metadata = $entity->getMetadata();
foreach ($metadata->getProperties() as $name => $metadataProperty) {
if ($metadataProperty->isVirtual) {
continue;
} elseif ($metadataProperty->isPrimary && !$entity->hasValue($name)) {
continue;
}
$property = $entity->getProperty($name);
if ($property instanceof IRelationshipCollection) {
continue;
}
if ($property instanceof IProperty) {
$value = $property->getRawValue();
} else {
$value = $entity->getValue($name);
}
$return[$name] = $value;
}
return $return;
}