Example #1
0
 public function testCanSerialize()
 {
     $datas = 'body document';
     $document = new Document('binary');
     $document->setDatas($datas)->setDescription('description document')->setEncoding('binary')->setSupport('data')->setName('file')->setId('id')->setWeight(12)->setSize('300x200')->setFormat('jpg');
     $serialize = serialize($document);
     // $this->assertEquals($serialize, 'C:21:"Dms\Document\Document":259:{a:10:{s:2:"id";s:2:"id";s:4:"size";s:7:"300x200";s:4:"name";s:4:"file";s:4:"type";s:10:"image/jpeg";s:4:"hash";s:2:"id";s:11:"description";s:20:"description document";s:8:"encoding";s:6:"binary";s:7:"support";s:4:"data";s:6:"weight";N;s:6:"format";s:3:"jpg";}}');
 }
Example #2
0
 /**
  * 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;
 }
Example #3
0
 public function testCanWriteData()
 {
     $path = __DIR__ . '/../../_upload/';
     $data = 'data write binary support data';
     $st = new Storage(array('path' => $path));
     $doc = new Document();
     $doc->setId('prfxfilename');
     $doc->setDatas($data);
     $res = $st->write($doc);
     $this->assertFileExists($path . 'pr/fx/filename.dat');
     $this->assertTrue(filesize($path . 'pr/fx/filename.dat') === strlen($data));
     $this->assertFileExists($path . 'pr/fx/filename.inf');
     $this->assertEquals(file_get_contents($path . 'pr/fx/filename.dat'), $data);
 }