Ejemplo n.º 1
0
 /**
  * Get a database object
  *
  * Returns a reference to the global {@link rDatabase} object, only creating it
  * if it doesn't already exist.
  *
  * @return object rDatabase
  */
 public static function &getDBO()
 {
     static $instance;
     if (!is_object($instance)) {
         $instance = ExpertsFactory::_createDBO();
     }
     return $instance;
 }
Ejemplo n.º 2
0
 /**
  * Returns a reference to the a Table object, always creating it
  *
  * @param type 		$type 	 The table type to instantiate
  * @param string 	$prefix	 A prefix for the table class name. Optional.
  * @param array		$options Configuration array for model. Optional.
  * @return database A database object
  * @since 1.5
  */
 function &getInstance($type, $prefix = 'bTable', $config = array())
 {
     $false = false;
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $tableClass = $prefix . ucfirst($type);
     if (!class_exists($tableClass)) {
         $file = DS . strtolower($type) . '.php';
         $path = false;
         foreach (bTable::addIncludePath() as $path) {
             if (is_file($path . $file)) {
                 $path = $path . $file;
                 break;
             }
         }
         if ($path) {
             require_once $path;
             if (!class_exists($tableClass)) {
                 trigger_error('Table class ' . $tableClass . ' not found in file.');
                 return $false;
             }
         } else {
             trigger_error('Table ' . $type . ' not supported. File not found.');
             return $false;
         }
     }
     //Make sure we are returning a DBO object
     if (array_key_exists('dbo', $config)) {
         $db =& $config['dbo'];
     } else {
         $db =& ExpertsFactory::getDBO();
     }
     $instance = new $tableClass($db);
     //$instance->setDBO($db);
     return $instance;
 }