<?php
/**
* Thin PHP Framework (TPF) 2011-2012 http://thinphp.com
* @package app.model.base.mongo
* @license TPF License http://bit.ly/TPFLicense
*/
defined('BASE') or exit('Direct script access is not allowed!');
abstract class MongoDBFactory
{
// Singleton pattern.
static $dbh;
/**
* @return Database Handler
*/
public static function getDBHandler()
{
if ( !isset(self::$dbh) )
{
global $mongodb_i;
$dbname = $mongodb_i['dbname'];
$ret = null;
try {
$replicaSet = trim($mongodb_i['replicaSet']);
if (strlen($replicaSet) > 0) {
$ret = new Mongo('mongodb://'.$mongodb_i['host'], array("replicaSet" => $replicaSet) );
} else {
$ret = new Mongo('mongodb://'.$mongodb_i['host'] );
}
$ret = $ret->$dbname; // select a database
}
catch(Exception $e)
{
die('MongoDBFactory: '.$e->getMessage());
}
self::$dbh = $ret;
return self::$dbh;
}
return self::$dbh;
}
}