ApiPlatform\Core\Hal\Serializer\ItemNormalizer::populateRelation PHP Метод

populateRelation() приватный метод

Populates _links and _embedded keys.
private populateRelation ( array $data, object $object, string $format = null, array $context, array $components, string $type ) : array
$data array
$object object
$format string
$context array
$components array
$type string
Результат array
    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;
    }