Example #1
0
 /**
  * Constructor for a file in use object. Should normally not be used
  * directly, use the corresponding factory methods instead.
  *
  * @param array $fileReferenceData
  * @param ResourceFactory $factory
  *
  * @throws \RuntimeException
  * @throws \InvalidArgumentException
  */
 public function __construct(array $fileReferenceData, $factory = null)
 {
     $this->propertiesOfFileReference = $fileReferenceData;
     if (!$fileReferenceData['uid_local']) {
         throw new \InvalidArgumentException('Incorrect reference to original file given for FileReference.', 1300098528);
     }
     if (!$factory) {
         /** @var $factory ResourceFactory */
         $factory = ResourceFactory::getInstance();
     }
     $this->originalFile = $factory->getFileObject($fileReferenceData['uid_local']);
     if (!is_object($this->originalFile)) {
         throw new \RuntimeException('Original file not found for FileReference. UID given: "' . $fileReferenceData['uid_local'] . '"', 1300098529);
     }
     $this->name = $fileReferenceData['name'] !== '' ? $fileReferenceData['name'] : $this->originalFile->getName();
 }