/** * @param \NilPortugues\Api\Mapping\Mapping[] $mappings * @param array $value * * @return array */ public static function setResponseDataTypeAndId(array &$mappings, array &$value) { if (empty($type = $value[Serializer::CLASS_IDENTIFIER_KEY]) || empty($mappings[$type])) { return []; } if (!is_scalar($type)) { return self::setResponseDataTypeAndId($mappings, $type); } $finalType = $mappings[$type]->getClassAlias() ? $mappings[$type]->getClassAlias() : $type; $ids = self::getIdValues($mappings, $value, $type); return [JsonApiTransformer::TYPE_KEY => RecursiveFormatterHelper::namespaceAsArrayKey($finalType), JsonApiTransformer::ID_KEY => \implode(JsonApiTransformer::ID_SEPARATOR, $ids)]; }
/** * @param \NilPortugues\Api\Mapping\Mapping[] $mappings * @param array $value * * @return array */ public static function setResponseDataTypeAndId(array &$mappings, array &$value) { $type = $value[Serializer::CLASS_IDENTIFIER_KEY]; if (empty($mappings[$type])) { return []; } if (!is_scalar($type)) { return self::setResponseDataTypeAndId($mappings, $type); } $finalType = $mappings[$type]->getClassAlias() ? $mappings[$type]->getClassAlias() : $type; $ids = []; foreach (\array_keys($value) as $propertyName) { if (\in_array($propertyName, RecursiveFormatterHelper::getIdProperties($mappings, $type), true)) { $id = RecursiveFormatterHelper::getIdValue($value[$propertyName]); $ids[] = \is_array($id) ? \implode(JsonApiTransformer::ID_SEPARATOR, $id) : $id; } } return [JsonApiTransformer::TYPE_KEY => RecursiveFormatterHelper::namespaceAsArrayKey($finalType), JsonApiTransformer::ID_KEY => \implode(JsonApiTransformer::ID_SEPARATOR, $ids)]; }
/** * @param string $aliasedClass * * @return $this */ public function setClassAlias(string $aliasedClass) { $this->classAlias = RecursiveFormatterHelper::camelCaseToUnderscore(RecursiveFormatterHelper::namespaceAsArrayKey($aliasedClass)); return $this; }