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"); }
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); }
/** * 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; }
/** * 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); }