Автор: Johannes Skov Frandsen (localgod@heaven.dk)
 public function testCurrent()
 {
     $this->assertEquals($this->object->current(), null);
     $this->object->next();
     $obj = $this->object->current();
     $this->assertNotNull($obj);
     $this->assertTrue($obj instanceof MongoGridFSFile);
 }
Пример #2
0
 /**
  * Writes the file to the system.
  * @param string $filename The location to which to write the file.
  * If none is given, the stored filename will be used.
  * @return integer number of bytes written or False on error.
  * @since v1.3
  */
 public function write($filename = null)
 {
     Yii::trace('Trace: ' . __CLASS__ . '::' . __FUNCTION__ . '()', 'ext.MongoDb.EMongoGridFS');
     if (method_exists($this->_gridFSFile, 'write') === true) {
         return $this->_gridFSFile->write($filename);
     } else {
         return false;
     }
 }
Пример #3
0
 /**
  * 显示/下载资源信息
  *
  * @param MongoGridFSFile $gridFsFile            
  */
 public function output(\MongoGridFSFile $gridFsFile, $output = true, $download = false)
 {
     $fileInfo = $gridFsFile->file;
     $fileName = $fileInfo['filename'];
     if ($output) {
         setHeaderExpires();
         if (isset($fileInfo['mime'])) {
             header('Content-Type: ' . $fileInfo['mime'] . ';');
         }
         if ($download) {
             header('Content-Disposition:attachment;filename="' . $fileName . '"');
         } else {
             header('Content-Disposition:filename="' . $fileName . '"');
         }
         $stream = $gridFsFile->getResource();
         while (!feof($stream)) {
             echo fread($stream, 8192);
         }
     } else {
         return $gridFsFile->getBytes();
     }
 }
Пример #4
0
 /**
  * Writes this file to the given filename path.
  *
  * @param string $filename
  * @return boolean TRUE if successful, and FALSE otherwise.
  */
 public function write($filename)
 {
     if ($this->isDirty && $this->bytes) {
         return file_put_contents($filename, $this->bytes);
     }
     if ($this->isDirty && $this->filename) {
         return copy($this->filename, $filename);
     }
     if ($this->mongoGridFSFile instanceof \MongoGridFSFile) {
         return $this->mongoGridFSFile->write($filename);
     }
     throw new \BadMethodCallException('Nothing to write(). File is not persisted yet and is not dirty.');
 }
 public function testWrite()
 {
     $bytes = $this->object->write('tests/anotherfile');
     $this->assertEquals($bytes, 129);
     $this->assertEquals(filesize('tests/anotherfile'), $this->object->getSize());
 }
 public function testGridFSProps()
 {
     $m = new Mongo();
     $grid = $m->foo->getGridFS();
     $x = new MongoGridFSFile($grid, array());
     $this->assertNull($x->getFilename());
     $this->assertNull($x->getSize());
 }
Пример #7
0
 /**
  * @param \MongoGridFS $gridFs
  * @param \MongoGridFSFile $file
  */
 function it_should_rename_file($gridFs, $file)
 {
     $file->getBytes()->willReturn('some content');
     $file->getSize()->willReturn(12);
     $gridFs->findOne('otherFilename', array())->willReturn(null);
     $gridFs->findOne('filename', array())->shouldBeCalled()->willReturn($file);
     $gridFs->storeBytes('some content', array('date' => 1234, 'filename' => 'otherFilename'))->shouldBeCalled()->willReturn('someId');
     $fileToDelete = new \stdClass();
     $fileToDelete->file = array('_id' => 123);
     $gridFs->findOne('filename', array('_id'))->willReturn($fileToDelete);
     $gridFs->findOne(array('_id' => 'someId'))->willReturn($file);
     $gridFs->delete(123)->shouldBeCalled()->willReturn(true);
     $this->setMetadata('otherFilename', array('date' => 1234));
     $this->rename('filename', 'otherFilename')->shouldReturn(true);
 }
 protected function format_stat(MongoGridFSFile $file)
 {
     return array("name" => $file->getFilename(), "size" => $file->getSize(), "ts" => $file->file['uploadDate']->sec, "mime" => $file->file['metadata']['mime'], "read" => true, "write" => true, "width" => $file->file['metadata']['width'], "height" => $file->file['metadata']['height']);
 }
Пример #9
0
 public function getResource()
 {
     return $this->file->getResource();
 }
 public function testWrite()
 {
     $bytes = $this->object->write('tests/classic.jpg');
     $this->assertEquals(13, $bytes);
 }