/** * @param mixed $source * @param string $targetType * @param array $convertedChildProperties * @param PropertyMappingConfigurationInterface|null $configuration * @return mixed|\Netlogix\JsonApiOrg\Schema\ResourceInterface|\TYPO3\Flow\Error\Error */ public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = null) { if (is_string($source)) { $sourceArray = json_decode($source, true); $source = is_array($sourceArray) ? $sourceArray : ['id' => $source]; } if (!array_key_exists('type', $source)) { $dummyPayload = $this->objectManager->get($targetType); $typeIdentifier = $dummyPayload->getType(); $source['type'] = $this->exposableTypeMap->getType($typeIdentifier); } if (array_key_exists('id', $source)) { $arguments = $source['id']; } else { $arguments = []; } $payload = $this->propertyMapper->convert($arguments, $this->exposableTypeMap->getClassName($source['type'])); $resourceInformation = $this->resourceMapper->findResourceInformation($payload); $resource = $resourceInformation->getResource($payload); if (isset($source['attributes'])) { $attributes = $resource->getAttributes(); foreach ($source['attributes'] as $fieldName => $value) { $attributes[$fieldName] = $value; } } if (isset($source['relationships'])) { $relationships = $resource->getRelationships(); foreach ($source['relationships'] as $fieldName => $value) { $relationships[$fieldName] = $value; } } return $resource; }
/** * @param ResourceInterface $resource * @return mixed */ protected function getEffektiveFieldsForResource(ResourceInterface $resource) { $type = $this->exposableTypeMap->getType($resource->getType()); if (array_key_exists($type, $this->fields)) { return $this->fields[$type]; } return null; }
/** * For any given $payload, the array structure holding the * public type identifier as well as the resource id is returned. * * @param mixed $payload * @return array * @see http://jsonapi.org/format/#document-resource-identifier-objects */ public function getDataIdentifierForPayload($payload) { $resourceInformation = $this->findResourceInformation($payload); $resource = $resourceInformation->getResource($payload); return array('type' => $this->exposableTypeMap->getType($resource->getType()), 'id' => $resource->getId()); }