/**
  * @param array $source
  * @param PropertyMappingConfigurationInterface $configuration
  * @return Resource|Error
  * @throws Exception
  */
 protected function handleFileUploads(array $source, PropertyMappingConfigurationInterface $configuration = null)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['originallySubmittedResource']) && isset($source['originallySubmittedResource']['__identity'])) {
             return $this->persistenceManager->getObjectByIdentifier($source['originallySubmittedResource']['__identity'], \TYPO3\Flow\Resource\Resource::class);
         }
         return null;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new Error(Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source, $this->getCollectionName($source, $configuration));
     if ($resource === false) {
         return new Error('The Resource Manager could not create a Resource instance for an uploaded file. See log for more details.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }
 /**
  * Actually convert from $source to $targetType, taking into account the fully
  * built $convertedChildProperties and $configuration.
  *
  * @param string|integer $source
  * @param string $targetType
  * @param array $convertedChildProperties
  * @param \TYPO3\CMS\Extbase\Property\PropertyMappingConfigurationInterface $configuration
  * @throws \TYPO3\CMS\Extbase\Property\Exception
  * @return \TYPO3\CMS\Extbase\Domain\Model\AbstractFileFolder
  * @api
  */
 public function convertFrom($source, $targetType, array $convertedChildProperties = array(), PropertyMappingConfigurationInterface $configuration = NULL)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['submittedFile']['resourcePointer'])) {
             try {
                 $resourcePointer = $this->hashService->validateAndStripHmac($source['submittedFile']['resourcePointer']);
                 if (strpos($resourcePointer, 'file:') === 0) {
                     $fileUid = substr($resourcePointer, 5);
                     return $this->createFileReferenceFromFalFileObject($this->resourceFactory->getFileObject($fileUid));
                 } else {
                     return $this->createFileReferenceFromFalFileReferenceObject($this->resourceFactory->getFileReferenceObject($resourcePointer), $resourcePointer);
                 }
             } catch (\InvalidArgumentException $e) {
                 // Nothing to do. No file is uploaded and resource pointer is invalid. Discard!
             }
         }
         return NULL;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new Error(Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     try {
         $resource = $this->importUploadedResource($source, $configuration);
     } catch (\Exception $e) {
         return new Error($e->getMessage(), $e->getCode());
     }
     $this->convertedResources[$source['tmp_name']] = $resource;
     return $resource;
 }
 /**
  * @param array $source
  * @return Resource|Error|NULL
  */
 protected function handleFileUploads(array $source)
 {
     if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
         if (isset($source['submittedFile']) && isset($source['submittedFile']['filename']) && isset($source['submittedFile']['resourcePointer'])) {
             $resourcePointer = $this->persistenceManager->getObjectByIdentifier($source['submittedFile']['resourcePointer'], 'TYPO3\\Flow\\Resource\\ResourcePointer');
             if ($resourcePointer) {
                 $resource = new Resource();
                 $resource->setFilename($source['submittedFile']['filename']);
                 $resource->setResourcePointer($resourcePointer);
                 return $resource;
             }
         }
         return NULL;
     }
     if ($source['error'] !== \UPLOAD_ERR_OK) {
         switch ($source['error']) {
             case \UPLOAD_ERR_INI_SIZE:
             case \UPLOAD_ERR_FORM_SIZE:
             case \UPLOAD_ERR_PARTIAL:
                 return new Error(Files::getUploadErrorMessage($source['error']), 1264440823);
             default:
                 $this->systemLogger->log(sprintf('A server error occurred while converting an uploaded resource: "%s"', Files::getUploadErrorMessage($source['error'])), LOG_ERR);
                 return new Error('An error occurred while uploading. Please try again or contact the administrator if the problem remains', 1340193849);
         }
     }
     if (isset($this->convertedResources[$source['tmp_name']])) {
         return $this->convertedResources[$source['tmp_name']];
     }
     $resource = $this->resourceManager->importUploadedResource($source);
     if ($resource === FALSE) {
         return new Error('The resource manager could not create a Resource instance.', 1264517906);
     } else {
         $this->convertedResources[$source['tmp_name']] = $resource;
         return $resource;
     }
 }