public function setUp() { // connect to mongo $client = new Client(); // select database $this->database = $client->map(array('test' => array('cars' => '\\Sokil\\Mongo\\DocumentRelationTest\\CarsCollection', 'engines' => '\\Sokil\\Mongo\\DocumentRelationTest\\EnginesCollection', 'wheels' => '\\Sokil\\Mongo\\DocumentRelationTest\\WheelsCollection', 'drivers' => '\\Sokil\\Mongo\\DocumentRelationTest\\DriversCollection', 'wrongRel' => '\\Sokil\\Mongo\\DocumentRelationTest\\WrongRelationCollection')))->getDatabase('test'); }
/** * Get instance of connection * * @param string $name connection identifier * @return \Sokil\Mongo\Client * @throws \Sokil\Mongo\Exception */ public function get($name) { // get from cache if (isset($this->pool[$name])) { return $this->pool[$name]; } // check if connection exists if (!isset($this->configuration[$name])) { throw new Exception('Connection with name ' . $name . ' not found'); } // check if dsn exists if (!isset($this->configuration[$name]['dsn'])) { $this->configuration[$name]['dsn'] = null; } // check if connect options exists if (empty($this->configuration[$name]['connectOptions'])) { $this->configuration[$name]['connectOptions'] = null; } // init client $client = new Client($this->configuration[$name]['dsn'], $this->configuration[$name]['connectOptions']); if (isset($this->configuration[$name]['mapping'])) { $client->map($this->configuration[$name]['mapping']); } if (isset($this->configuration[$name]['defaultDatabase'])) { $client->useDatabase($this->configuration[$name]['defaultDatabase']); } $this->pool[$name] = $client; return $client; }