protected function getDocumentHash(Document $document)
{
$hash = array();
foreach ($document->fields as $field) {
if ($field->type instanceof DocumentField) {
$documents = $this->fieldValueMapper->map($field);
$values = array();
foreach ($documents as $document) {
$values[] = $this->getDocumentHash($document);
}
} else {
$values = (array) $this->fieldValueMapper->map($field);
}
$name = $this->nameGenerator->getTypedName($field->name, $field->type);
if (count($values) === 1) {
$hash[$name] = reset($values);
} else {
$hash[$name] = $values;
}
}
return $hash;
}