/**
  * @param string $propertyPath
  * @param null $additionalReferenceProperties
  * @return \CIC\Cicbase\Domain\Model\FileReference
  */
 protected function buildFileReference($propertyPath, $additionalReferenceProperties = NULL)
 {
     $pathExists = $this->temporaryPathExists();
     $relFolderPath = $this->buildTemporaryPath(FALSE);
     $folder = $this->createFolderObject($relFolderPath, $pathExists);
     // Folder data from $_FILES
     $source = $this->getUploadedFileData($propertyPath);
     // Use the file hash as the name of the file
     $originalFilename = $source['name'];
     $source['name'] = md5_file($source['tmp_name']) . '.' . pathinfo($source['name'], PATHINFO_EXTENSION);
     // Create the FileObject by adding the uploaded file to the FolderObject.
     $file = $folder->addUploadedFile($source, 'replace');
     // Default properties for our reference object from our File object.
     $referenceProperties = array('uid_local' => $file->getUid(), 'table_local' => 'sys_file', 'title' => $originalFilename);
     // Allow for additional reference properties to be added
     if (is_array($additionalReferenceProperties)) {
         $referenceProperties = array_merge($referenceProperties, $additionalReferenceProperties);
     }
     // Build a FileReference object using our reference properties
     $ref = $this->fileFactory->createFileReferenceObject($referenceProperties);
     // Convert the Core FileReference we made to an CICBase FileReference
     $fileReference = $this->objectManager->getEmptyObject('CIC\\Cicbase\\Domain\\Model\\FileReference');
     $fileReference->setOriginalResource($ref);
     return $fileReference;
 }
Exemple #2
0
 /**
  * Creates a skeleton of the specified object
  *
  * @param string $className Name of the class to create a skeleton for
  * @throws CannotReconstituteObjectException
  * @return object The object skeleton
  */
 protected function createEmptyObject($className)
 {
     // Note: The class_implements() function also invokes autoload to assure that the interfaces
     // and the class are loaded. Would end up with __PHP_Incomplete_Class without it.
     if (!in_array(\TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface::class, class_implements($className))) {
         throw new CannotReconstituteObjectException('Cannot create empty instance of the class "' . $className . '" because it does not implement the TYPO3\\CMS\\Extbase\\DomainObject\\DomainObjectInterface.', 1234386924);
     }
     $object = $this->objectManager->getEmptyObject($className);
     return $object;
 }