/** * @param array $source * @param PropertyMappingConfigurationInterface $configuration * @return Resource|Error * @throws Exception * @throws InvalidPropertyMappingConfigurationException */ protected function handleHashAndData(array $source, PropertyMappingConfigurationInterface $configuration = null) { $hash = null; $resource = false; $givenResourceIdentity = null; if (isset($source['__identity'])) { $givenResourceIdentity = $source['__identity']; unset($source['__identity']); $resource = $this->resourceRepository->findByIdentifier($givenResourceIdentity); if ($resource instanceof Resource) { return $resource; } if ($configuration->getConfigurationValue(\TYPO3\Flow\Resource\ResourceTypeConverter::class, self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== true) { throw new InvalidPropertyMappingConfigurationException('Creation of resource objects with identity not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_IDENTITY_CREATION_ALLOWED" to TRUE'); } } if (isset($source['hash']) && preg_match('/[0-9a-f]{40}/', $source['hash'])) { $hash = $source['hash']; } if ($hash !== null && count($source) === 1) { $resource = $this->resourceManager->getResourceBySha1($hash); } if ($resource === null) { $collectionName = $this->getCollectionName($source, $configuration); if (isset($source['data'])) { $resource = $this->resourceManager->importResourceFromContent($source['data'], $source['filename'], $collectionName, $givenResourceIdentity); } elseif ($hash !== null) { $resource = $this->resourceManager->importResource($configuration->getConfigurationValue(\TYPO3\Flow\Resource\ResourceTypeConverter::class, self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash, $collectionName, $givenResourceIdentity); if (is_array($source) && isset($source['filename'])) { $resource->setFilename($source['filename']); } } } if ($resource instanceof Resource) { return $resource; } else { return new Error('The resource manager could not create a Resource instance.', 1404312901); } }