예제 #1
0
파일: Factory.php 프로젝트: ngchie/system
 /**
  * method to retrieve the db instance
  * 
  * @return Billrun_Db
  */
 public static function db(array $options = array())
 {
     $mainDb = 0;
     if (empty($options)) {
         $options = Billrun_Factory::config()->getConfigValue('db');
         // the stdclass force it to return object
         $mainDb = 1;
     } else {
         if (isset($options['name']) && count($options) == 1) {
             $name = $options['name'];
             $options = Billrun_Factory::config()->getConfigValue('db');
             $seperateDatabaseCollections = isset($options['seperateDatabaseCollections']) ? $options['seperateDatabaseCollections'] : array('balances', 'billrunstats', 'billrun');
             // until mongo will do collection lock
             if (in_array($name, $seperateDatabaseCollections)) {
                 $options['name'] = $name;
             }
         }
     }
     // unique stamp per db connection
     $stamp = md5(serialize($options));
     if (!isset(self::$db[$stamp])) {
         self::$db[$stamp] = Billrun_Db::getInstance($options);
         if ($mainDb) {
             Billrun_Factory::config()->loadDbConfig();
         }
     }
     return self::$db[$stamp];
 }
예제 #2
0
 /**
  * method to retrieve the db instance
  * 
  * @return Billrun_Db
  */
 public static function db(array $options = array())
 {
     if (empty($options)) {
         $options = Billrun_Factory::config()->getConfigValue('db');
         // the stdclass force it to return object
     } else {
         if (isset($options['name']) && in_array($options['name'], array('balances', 'billrunstats')) && count($options) == 1) {
             $name = $options['name'];
             // move balances to different database
             $options = Billrun_Factory::config()->getConfigValue('db');
             $options['name'] = $name;
         }
     }
     // unique stamp per db connection
     $stamp = md5(serialize($options));
     if (!isset(self::$db[$stamp])) {
         self::$db[$stamp] = Billrun_Db::getInstance($options);
     }
     return self::$db[$stamp];
 }