#1 cooc123
/**
* import 载入包含文件
*
* @param filename 需要载入的文件名或者文件路径
* @param auto_search 载入文件找不到时是否搜索系统路径或文件,搜索路径的顺序为:应用程序包含目录 -> 应用程序Model目录 -> sp框架包含文件目录
* @param auto_error 自动提示扩展类载入出错信息
*/
function import($sfilename, $auto_search = TRUE, $auto_error = FALSE){
if(isset($GLOBALS['G_SP']["import_file"][md5($sfilename)]))return TRUE; // 已包含载入,返回
// 检查$sfilename是否直接可读
if( TRUE == @is_readable($sfilename) ){
require($sfilename); // 载入文件
$GLOBALS['G_SP']['import_file'][md5($sfilename)] = TRUE; // 对该文件进行标识为已载入
return TRUE;
}else{
if(TRUE == $auto_search){ // 需要搜索文件
// 按“应用程序包含目录 -> 应用程序Model目录 -> sp框架包含文件目录”的顺序搜索文件
foreach(array_merge( $GLOBALS['G_SP']['include_path'], array($GLOBALS['G_SP']['model_path']), $GLOBALS['G_SP']['sp_include_path'] ) as $sp_include_path){
// 检查当前搜索路径中,该文件是否已经载入
if(isset($GLOBALS['G_SP']["import_file"][md5($sp_include_path.'/'.$sfilename)]))return TRUE;
if( is_readable( $sp_include_path.'/'.$sfilename ) ){
require($sp_include_path.'/'.$sfilename);// 载入文件
$GLOBALS['G_SP']['import_file'][md5($sp_include_path.'/'.$sfilename)] = TRUE;// 对该文件进行标识为已载入
return TRUE;
}
}
}
}
if( TRUE == $auto_error )spError("未能找到名为:{$sfilename}的文件");
// 这里怎样运行的,如果上面没有搜索到文件 也没有将 $auto_error 设置为TRUE啊
return FALSE;
}
2012-01-11 16:16:46