/** * @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; }
/** * Only convert non-persistent types * * @param mixed $source * @param string $targetType * @return boolean */ public function canConvertFrom($source, $targetType) { if (!is_array($source) || !array_key_exists('type', $source)) { return false; } try { $className = $this->exposableTypeMap->getClassName($source['type']); } catch (FormatNotSupportedException $e) { return false; } if ($className !== $targetType && !is_subclass_of($className, $targetType) && !is_subclass_of($targetType, $className)) { return false; } return !!$this->resourceMapper->findResourceInformation($className); }
/** * @param mixed $resource * @param string $controllerActionName * @param array $controllerArguments * @return Uri */ protected function getPublicUri($resource, $controllerActionName, array $controllerArguments = array()) { $uriBuilder = $this->resourceMapper->getControllerContext()->getUriBuilder(); $uriBuilder->reset()->setFormat($this->format)->setCreateAbsoluteUri(true); $uri = $uriBuilder->uriFor($controllerActionName, array_merge($this->getResourceControllerArguments($resource), $controllerArguments), $this->controllerName, $this->packageKey, $this->subPackageKey); return new Uri($uri); }
/** * @param $payload * @return array */ protected function getDataIdentifierForPayload($payload) { return $this->resourceMapper->getDataIdentifierForPayload($payload); }
/** * @param array $relation * @return string */ protected function getResourceUriForArrayFormat($relation) { $resource = $this->propertyMapper->convert((string) $relation['id'], $this->exposableTypeMap->getClassName($relation['type'])); $resourceInformation = $this->resourceMapper->findResourceInformation($resource); return $resourceInformation->getPublicResourceUri($resource); }