Sokil\Mongo\Database::getCollection PHP Method

getCollection() public method

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

Usage Example

Example #1
0
 public function testGetOptions()
 {
     // define array of collections
     $this->database->map(array('collection1' => array('someOption' => 'someValue')));
     $options = $this->database->getCollection('collection1')->getOptions();
     $this->assertArrayHasKey('someOption', $options);
     $this->assertEquals($options['someOption'], 'someValue');
 }
All Usage Examples Of Sokil\Mongo\Database::getCollection