/** * @param array $source * @param PropertyMappingConfigurationInterface $configuration * @return Resource|Error */ 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->persistenceManager->getObjectByIdentifier($givenResourceIdentity, 'TYPO3\\Flow\\Resource\\Resource'); if ($resource instanceof \TYPO3\Flow\Resource\Resource) { return $resource; } if ($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_IDENTITY_CREATION_ALLOWED) !== TRUE) { throw new \TYPO3\Flow\Property\Exception\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) { $resourcePointer = $this->persistenceManager->getObjectByIdentifier($hash, 'TYPO3\\Flow\\Resource\\ResourcePointer'); if ($resourcePointer) { $resource = new Resource(); $resource->setFilename($source['filename']); $resource->setResourcePointer($resourcePointer); } } if ($resource === NULL) { if (isset($source['data'])) { $resource = $this->resourceManager->createResourceFromContent($source['data'], $source['filename']); } elseif ($hash !== NULL) { $resource = $this->resourceManager->importResource($configuration->getConfigurationValue('TYPO3\\Flow\\Resource\\ResourceTypeConverter', self::CONFIGURATION_RESOURCE_LOAD_PATH) . '/' . $hash); if (is_array($source) && isset($source['filename'])) { $resource->setFilename($source['filename']); } } } if ($resource instanceof \TYPO3\Flow\Resource\Resource) { if ($givenResourceIdentity !== NULL) { $this->setIdentity($resource, $givenResourceIdentity); } return $resource; } else { return new Error('The resource manager could not create a Resource instance.', 1404312901); } }
/** * Imports a resource based on exported hash or content * * @param string $fileName * @param string|null $hash * @param string|null $content * @param string $forcedIdentifier * @return \TYPO3\Flow\Resource\Resource * @throws NeosException */ protected function importResource($fileName, $hash = null, $content = null, $forcedIdentifier = null) { if ($hash !== null) { $resource = $this->resourceManager->createResourceFromContent(file_get_contents(Files::concatenatePaths(array($this->resourcesPath, $hash))), $fileName); } else { $resourceData = trim($content); if ($resourceData === '') { throw new NeosException('Could not import resource because neither "hash" nor "content" tags are present.', 1403009453); } $decodedResourceData = base64_decode($resourceData); if ($decodedResourceData === false) { throw new NeosException('Could not import resource because the "content" tag doesn\'t contain valid base64 encoded data.', 1403009477); } $resource = $this->resourceManager->createResourceFromContent($decodedResourceData, $fileName); } if ($forcedIdentifier !== null) { ObjectAccess::setProperty($resource, 'Persistence_Object_Identifier', $forcedIdentifier, true); } return $resource; }