Sokil\Mongo\Database::getGridFS PHP Method

getGridFS() public method

Get instance of GridFS
public getGridFS ( string $name = 'fs' ) : GridFS
$name string prefix of files and chunks collection
return GridFS
    public function getGridFS($name = 'fs')
    {
        // return from pool
        if ($this->collectionPoolEnabled && isset($this->collectionPool[$name])) {
            return $this->collectionPool[$name];
        }
        // no object in pool - init new
        $classDefinition = $this->getCollectionDefinition($name, array('gridfs' => true));
        $className = $classDefinition->getClass();
        // create collection class
        $collection = new $className($this, $name, $classDefinition);
        if (!$collection instanceof \Sokil\Mongo\GridFS) {
            throw new Exception('Must be instance of \\Sokil\\Mongo\\GridFS');
        }
        // store to pool
        if ($this->collectionPoolEnabled) {
            $this->collectionPool[$name] = $collection;
        }
        // return
        return $collection;
    }

Usage Example

Example #1
0
 /**
  * @expectedException \Sokil\Mongo\Exception
  * @expectedExceptionMessage Must be instance of \Sokil\Mongo\GridFS
  */
 public function testGetGridFs_SpecifiedGridFSClassInMappingIsNotInstanceOfGridFS()
 {
     $this->database->map(array('gridfs' => '\\stdClass'));
     $this->database->getGridFS('gridfs');
     $this->fail('Must be exception');
 }