/**
  * @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;
 }
Example #2
0
 /**
  * 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());
 }
 /**
  * @param $source
  * @return mixed
  */
 protected function convertIdentifierProperties($source)
 {
     $identifier = array_key_exists('id', $source) ? $source['id'] : [];
     return $this->propertyMapper->convert($identifier, $this->exposableTypeMap->getClassName($source['type']));
 }
 /**
  * @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);
 }