/** * {@inheritdoc} * * @param \Dms\Document\Document $document * * @see \Dms\Storage\StorageInterface::write() */ public function write(\Dms\Document\Document $document) { $ret = null; $name = $document->getId(); $nameMod = substr($name, 4); $f = substr($name, 0, 2) . '/' . substr($name, 2, 2) . '/'; $path = $this->getBasePath() . $f; if (!is_dir($path)) { mkdir($path, 0777, true); } $p = $path . $nameMod . '.dat'; if ($document->getSupport() === Document::SUPPORT_FILE_MULTI_PART_STR) { $fileInput = new FileInput(key($document->getDatas())); $fileInput->getFilterChain()->attachByName('filerenameupload', ['target' => $p]); $inputFilter = new InputFilter(); $inputFilter->add($fileInput); $form = new Form(); $form->setInputFilter($inputFilter); $form->setData($document->getDatas()); if ($form->isValid()) { $form->getData(); } } else { $fp = fopen($p, 'w'); fwrite($fp, $document->getDatas()); $document->setWeight(strlen($document->getDatas())); fclose($fp); } $conf_storage = $this->options->getStorage(); if (isset($conf_storage['name']) && $conf_storage['name'] === 's3') { print_r($_FILES); $this->s3Client->copyObject(['Bucket' => $conf_storage['bucket'], 'Key' => $f . $nameMod . '.dat', 'CopySource' => $conf_storage['bucket'] . '/' . $f . $nameMod . '.dat', 'ContentType' => $document->getType(), 'ContentDisposition' => sprintf('filename=%s', null === $document->getName() ? substr($file, -1 * strlen($document->getFormat())) === $document->getFormat() ? $file : $file . '.' . $document->getFormat() : $document->getName()), 'MetadataDirective' => 'REPLACE']); } $document->setSupport(Document::SUPPORT_FILE_STR); $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . '.dat', 'support' => $document->getSupport(), 'name' => $name)); $serialize = serialize($document); $fp = fopen($path . $nameMod . '.inf', 'w'); $ret += fwrite($fp, $serialize); fclose($fp); $this->getEventManager()->trigger(__FUNCTION__, $this, array('path' => $path, 'short_name' => $nameMod, 'all_path' => $path . $nameMod . 'inf', 'support' => $document->getSupport(), 'name' => $name)); return $ret; }
/** * Decode Document to binary. * * @throws \Exception * * @return \Dms\Document\Manager */ public function decode() { if (null === $this->document) { throw new \Exception('Document does not exist'); } if ($this->document->getEncoding() != Document::TYPE_BINARY_STR && $this->document->getSupport() == Document::SUPPORT_DATA_STR) { $this->document->setDatas($this->getEncDec($this->document->getEncoding())->decode($this->document->getDatas())); $this->document->setEncoding(Document::TYPE_BINARY_STR); } return $this; }
public function testCanGetSupportDefault() { $document = new Document(); $sup = $document->getSupport(); $this->assertEquals($sup, 'data'); }