getGridFS() public méthode

Fetches toolkit for dealing with files stored in this database
public getGridFS ( string $prefix = "fs" ) : MongoGridFS
$prefix string The prefix for the files and chunks collections.
Résultat MongoGridFS Returns a new gridfs object for this database.
 public function testGetGridFS()
 {
     if (preg_match("/5\\.1\\../", phpversion())) {
         $this->markTestSkipped("No implicit __toString in 5.1");
         return;
     }
     $grid = $this->object->getGridFS();
     $this->assertTrue($grid instanceof MongoGridFS);
     $this->assertTrue($grid instanceof MongoCollection);
     $this->assertEquals((string) $grid, "phpunit.fs.files");
     $this->assertEquals((string) $grid->chunks, "phpunit.fs.chunks");
     $grid = $this->object->getGridFS("foo");
     $this->assertEquals((string) $grid, "phpunit.foo.files");
     $this->assertEquals((string) $grid->chunks, "phpunit.foo.chunks");
     $grid = $this->object->getGridFS("foo", "bar");
     $this->assertEquals((string) $grid, "phpunit.foo.files");
     $this->assertEquals((string) $grid->chunks, "phpunit.foo.chunks");
 }
Exemple #2
0
 public function gridFS($arg1 = NULL, $arg2 = NULL)
 {
     $this->_connected or $this->connect();
     if (!isset($arg1)) {
         $arg1 = isset($this->_config['gridFS']['arg1']) ? $this->_config['gridFS']['arg1'] : 'fs';
     }
     if (!isset($arg2) && isset($this->_config['gridFS']['arg2'])) {
         $arg2 = $this->_config['gridFS']['arg2'];
     }
     return $this->_db->getGridFS($arg1, $arg2);
 }
Exemple #3
0
	/**
	 * Saves a file to MongoDB
	 *
	 * @param string $filePath
	 * @param array $oldReference
	 * @return mixed The id of the stored file
	 */
	public function saveFile($filePath, $oldReference = null)
	{
		$id = null;
		if (file_exists($filePath)) {
			if (!empty($oldReference)) {
				$this->db->getGridFS()->remove(array('_id' => $oldReference), true); //remove existing file
			}
			$id = $this->db->getGridFS()->storeFile($filePath);
		} else {
			throw new \InvalidArgumentException("The file $filePath does not exist");
		}
		return $id;
	}
Exemple #4
0
 /**
  * Return a new GridFS instance.
  *
  * @see Database::getGridFS()
  * @param string $prefix
  * @return GridFS
  */
 protected function doGetGridFS($prefix)
 {
     $mongoGridFS = $this->mongoDB->getGridFS($prefix);
     return new GridFS($this, $mongoGridFS, $this->eventManager);
 }