コード例 #1
0
 public function _autoloadClass($class, $table = false)
 {
     // avoid those annoying PEAR::DB strict standards warnings it causes
     $old = error_reporting();
     error_reporting(error_reporting() & ~E_STRICT);
     $res = parent::_autoloadClass($class, $table);
     // reset
     error_reporting($old);
     return $res;
 }
コード例 #2
0
ファイル: DataObject.php プロジェクト: bigpussy/statusnet
 /**
  * classic factory method for loading a table class
  * usage: $do = DB_DataObject::factory('person')
  * WARNING - this may emit a include error if the file does not exist..
  * use @ to silence it (if you are sure it is acceptable)
  * eg. $do = @DB_DataObject::factory('person')
  *
  * table name can bedatabasename/table
  * - and allow modular dataobjects to be written..
  * (this also helps proxy creation)
  *
  * Experimental Support for Multi-Database factory eg. mydatabase.mytable
  * 
  * 
  * @param  string  $table  tablename (use blank to create a new instance of the same class.)
  * @access private
  * @return DataObject|PEAR_Error 
  */
 function factory($table = '')
 {
     global $_DB_DATAOBJECT;
     // multi-database support.. - experimental.
     $database = '';
     if (strpos($table, '/') !== false) {
         list($database, $table) = explode('.', $table, 2);
     }
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     // no configuration available for database
     if (!empty($database) && empty($_DB_DATAOBJECT['CONFIG']['database_' . $database])) {
         return DB_DataObject::raiseError("unable to find database_{$database} in Configuration, It is required for factory with database", 0, PEAR_ERROR_DIE);
     }
     if ($table === '') {
         if (is_a($this, 'DB_DataObject') && strlen($this->__table)) {
             $table = $this->__table;
         } else {
             return DB_DataObject::raiseError("factory did not recieve a table name", DB_DATAOBJECT_ERROR_INVALIDARGS);
         }
     }
     // does this need multi db support??
     $cp = isset($_DB_DATAOBJECT['CONFIG']['class_prefix']) ? explode(PATH_SEPARATOR, $_DB_DATAOBJECT['CONFIG']['class_prefix']) : '';
     // multiprefix support.
     $tbl = preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table));
     if (is_array($cp)) {
         $class = array();
         foreach ($cp as $cpr) {
             $ce = substr(phpversion(), 0, 1) > 4 ? class_exists($cpr . $tbl, false) : class_exists($cpr . $tbl);
             if ($ce) {
                 $class = $cpr . $tbl;
                 break;
             }
             $class[] = $cpr . $tbl;
         }
     } else {
         $class = $tbl;
         $ce = substr(phpversion(), 0, 1) > 4 ? class_exists($class, false) : class_exists($class);
     }
     $rclass = $ce ? $class : DB_DataObject::_autoloadClass($class, $table);
     // proxy = full|light
     if (!$rclass && isset($_DB_DATAOBJECT['CONFIG']['proxy'])) {
         DB_DataObject::debug("FAILED TO Autoload  {$database}.{$table} - using proxy.", "FACTORY", 1);
         $proxyMethod = 'getProxy' . $_DB_DATAOBJECT['CONFIG']['proxy'];
         // if you have loaded (some other way) - dont try and load it again..
         class_exists('DB_DataObject_Generator') ? '' : (require_once 'DB/DataObject/Generator.php');
         $d = new DB_DataObject();
         $d->__table = $table;
         if (is_a($ret = $d->_connect(), 'PEAR_Error')) {
             return $ret;
         }
         $x = new DB_DataObject_Generator();
         return $x->{$proxyMethod}($d->_database, $table);
     }
     if (!$rclass) {
         return DB_DataObject::raiseError("factory could not find class " . (is_array($class) ? implode(PATH_SEPARATOR, $class) : $class) . "from {$table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
     }
     $ret = new $rclass();
     if (!empty($database)) {
         DB_DataObject::debug("Setting database to {$database}", "FACTORY", 1);
         $ret->database($database);
     }
     return $ret;
 }
コード例 #3
0
 /**
  * classic factory method for loading a table class
  * usage: $do = DB_DataObject::factory('person')
  * WARNING - this may emit a include error if the file does not exist..
  * use @ to silence it (if you are sure it is acceptable)
  * eg. $do = @DB_DataObject::factory('person')
  *
  * table name will eventually be databasename/table
  * - and allow modular dataobjects to be written..
  * (this also helps proxy creation)
  *
  *
  * @param  string  $table  tablename (use blank to create a new instance of the same class.)
  * @access private
  * @return DataObject|PEAR_Error 
  */
 function factory($table = '')
 {
     global $_DB_DATAOBJECT;
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     if ($table === '') {
         if (is_a($this, 'DB_DataObject') && strlen($this->__table)) {
             $table = $this->__table;
         } else {
             return DB_DataObject::raiseError("factory did not recieve a table name", DB_DATAOBJECT_ERROR_INVALIDARGS);
         }
     }
     $p = isset($_DB_DATAOBJECT['CONFIG']['class_prefix']) ? $_DB_DATAOBJECT['CONFIG']['class_prefix'] : '';
     $class = $p . preg_replace('/[^A-Z0-9]/i', '_', ucfirst($table));
     $class = class_exists($class) ? $class : DB_DataObject::_autoloadClass($class);
     // proxy = full|light
     if (!$class && isset($_DB_DATAOBJECT['CONFIG']['proxy'])) {
         $proxyMethod = 'getProxy' . $_DB_DATAOBJECT['CONFIG']['proxy'];
         require_once 'DB/DataObject/Generator.php';
         $d = new DB_DataObject();
         $d->__table = $table;
         $d->_connect();
         $x = new DB_DataObject_Generator();
         return $x->{$proxyMethod}($d->_database, $table);
     }
     if (!$class) {
         return DB_DataObject::raiseError("factory could not find class {$class} from {$table}", DB_DATAOBJECT_ERROR_INVALIDCONFIG);
     }
     return new $class();
 }
コード例 #4
0
ファイル: M.php プロジェクト: demental/m
 public static function m_autoload_db_dataobject($class)
 {
     $classname = strtolower($class);
     if (strpos($classname, 'dataobjects_') === 0) {
         return DB_DataObject::_autoloadClass($classname);
     } else {
         return false;
     }
 }
コード例 #5
0
ファイル: DataObject.php プロジェクト: vojtajina/sitellite
 /**
  * autoload Class relating to a table
  *
  * @param  string  $table  table
  * @access private
  * @return string classname on Success
  */
 function staticAutoloadTable($table)
 {
     global $_DB_DATAOBJECT;
     if (empty($_DB_DATAOBJECT['CONFIG'])) {
         DB_DataObject::_loadConfig();
     }
     $class = DB_DataObject::_autoloadClass($_DB_DATAOBJECT['CONFIG']['class_prefix'] . ucfirst($table));
     return $class;
 }