init($config); } return self::$instance[$key]; } /** * init * * @return mixd */ private function init($config) { if(strpos($config['host'], ':') !== false) list($config['host'], $config['port']) = explode(':', $config['host']); try { $mongo = new \Mongo('mongodb://'.$config['host'].':'.$config['port'], array("connectTimeoutMS"=>1000)); $this->handle = $mongo->selectDB($config['database']); Debug::log('mongodb ' . $config['host'] . ' connected'); } catch(\PDOException $e) { echo $e->getMessage();die; } } /** * __destruct * * @return mixd */ public function __destruct() { $this->close(); } /** * table * * @return mixd */ public function table($table) { return $this->handle->selectCollection($table); } /** * handle * * @return object */ public function handle() { return $this->handle; } /** * close * * @return mixd */ public function close() { $this->handle = null; } }