/** * autoload Class * * @param string $class Class * @access protected * @return string classname on Success */ function _autoloadClass($table, $database) { if (empty(DB_DataObject2::$CONFIG)) { DB_DataObject2::_loadConfig(); } $class_prefix = empty(DB_DataObject2::$CONFIG['class_prefix']) ? '' : DB_DataObject2::$CONFIG['class_prefix']; // only include the file if it exists - and barf badly if it has parse errors :) if (!empty(DB_DataObject2::$CONFIG['proxy']) || empty(DB_DataObject2::$CONFIG['class_location'])) { return false; } if (is_array(DB_DataObject2::$CONFIG['class_location'])) { $class_locations = DB_DataObject2::$CONFIG['class_location']; } else { $class_locations = array(DB_DataObject2::$CONFIG['class_location']); } $found = false; foreach (array_reverse($class_locations) as $location) { if (strpos($location, '%s') !== false) { $file = sprintf($location, preg_replace('/[^A-Z0-9]/i', '_', ucfirst(trim($database . '_' . $table)))); } else { $file = $location . '/' . preg_replace('/[^A-Z0-9]/i', '_', ucfirst(trim($database . '_' . $table))) . ".php"; } if (!file_exists($file)) { foreach (explode(PATH_SEPARATOR, ini_get('include_path')) as $p) { if (file_exists("{$p}/{$file}")) { $file = "{$p}/{$file}"; $found = true; break; } } } else { $found = true; break; } if ($found) { break; } } if (!$found) { DB_DataObject2::raiseError("autoload:Could not find table/database {$table}/{$database} using class_location value", DB_DATAOBJECT_ERROR_INVALIDCONFIG); return false; } require_once $file; $p = isset(DB_DataObject2::$CONFIG['class_prefix']) ? DB_DataObject2::$CONFIG['class_prefix'] : ''; $class = $p . ucfirst(trim($database . '_' . $table)); $ce = class_exists($class, false); if (!$ce) { DB_DataObject2::raiseError("autoload:Could not autoload {$class}", DB_DATAOBJECT_ERROR_INVALIDCONFIG); return false; } return $class; }