map() public method

Map collection name to class
public map ( string | array $name, string | array | Definition | null $classDefinition = null ) : Client
$name string | array collection name or array like [collectionName => collectionClass, ...]
$classDefinition string | array | Sokil\Mongo\Collection\Definition | null if $name is string, then full class name or array with parameters, else omitted
return Client
Example #1
0
 public function testIsVersioningEnabled()
 {
     // set by property
     $this->database->map('col1', '\\Sokil\\Mongo\\CollectionWithVersioningMock');
     $this->assertTrue($this->database->col1->isVersioningEnabled());
     // set by map definition
     $this->database->map('col2', array('versioning' => true));
     $this->assertTrue($this->database->col2->isVersioningEnabled());
     // set by map definition
     $this->database->map('col3', array('versioning' => false));
     $this->assertFalse($this->database->col3->isVersioningEnabled());
 }
Example #2
0
 /**
  * 
  * @param string $name database name
  * @return \Sokil\Mongo\Database
  */
 public function getDatabase($name = null)
 {
     if (!$name) {
         $name = $this->getCurrentDatabaseName();
     }
     if (!isset($this->databasePool[$name])) {
         // init db
         $database = new Database($this, $name);
         if (isset($this->_mapping[$name])) {
             $database->map($this->_mapping[$name]);
         }
         // configure db
         $this->databasePool[$name] = $database;
     }
     return $this->databasePool[$name];
 }
Example #3
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');
 }
Example #4
0
 public function testSetServerTimeoutInMapping()
 {
     $this->database->map('col', array('cursorServerTimeout' => 42));
     $cursor = $this->database->getCollection('col')->find();
     $this->assertEquals(42, $cursor->getOption('serverTimeout'));
 }