private function populateRelation(array $data, $object, string $format = null, array $context, array $components, string $type) : array
{
$key = '_' . $type;
foreach ($components[$type] as $relation) {
$attributeValue = $this->getAttributeValue($object, $relation['name'], $format, $context);
if (empty($attributeValue)) {
continue;
}
if ('one' === $relation['cardinality']) {
if ('links' === $type) {
$data[$key][$relation['name']]['href'] = $this->getRelationIri($attributeValue);
continue;
}
$data[$key][$relation['name']] = $attributeValue;
continue;
}
// many
$data[$key][$relation['name']] = [];
foreach ($attributeValue as $rel) {
if ('links' === $type) {
$rel = ['href' => $this->getRelationIri($rel)];
}
$data[$key][$relation['name']][] = $rel;
}
}
return $data;
}