php中自定义自动加载函数
来源:互联网 发布:属于淘宝禁售商品刀 编辑:程序博客网 时间:2024/04/28 15:14
//定义自己的自动加载函数
class AutoLoad{
public function __construct(){
spl_autoload_register(array($this, 'autoLoad'));
}
pulblic static function autoLoad($class_name){
$app_domain = AppDomain::get();
if(!$app_domain){
trigger_error('Must define the APP_DOMAIN in the entry!', E_USER_ERROR);
}
$app_cls_domain_arr = explode('_', $app_domain);
$app_cls_domain = $app_cls_domain_arr[0];
$ap_key_fmt = "class_%s_{$className}_location";
$class_domain_arr = array($app_cls_domain, 'common');
$file_path = null;
$apc_loaded = extension_loaded('apc');
if($apc_loaded){
foreach($class_domain_arr as $domain){
$ap_key_str = sprintf($ap_key_fmt, $domain);
if($file_path = apc_fetch($ap_key_str)){
break;
}
}
}
if(is_file($file_path)){
require_once($file_path);
return true;
}
//这里要提前规定好 你存放一些class类的地址,然后才好去寻找
// find class in the app class or common dir
$app_class_dir = GLOBAL_BASE_PATH . 'classes/apps/' . $app_cls_domain;
$common_class_dir = GLOBAL_BASE_PATH . 'classes/common';
$class_dir_arr = array($app_class_dir, $common_class_dir);
$class_dir_arr_assoc = array_combine($class_domain_arr, $class_dir_arr);
foreach($class_dir_arr_assoc as $domain=>$dir){
$class_real_dir = realpath($dir);
$cls_file_name = $className . '.php';
$key = array_search($cls_file_name, scandir($class_real_dir));
$file_path = $class_real_dir . '/' . ($key === false ? null : $cls_file_name);
if(is_file($file_path)){
if($apc_loaded){
$ap_key_str = sprintf($ap_key_fmt, $domain);
apc_store($ap_key_str, $file_path);
}
require_once($file_path);
return true;
}
}
return false;
}
}
- php中自定义自动加载函数
- PHP自动加载函数
- php自动加载函数
- PHP中spl_autoload_register函数的用法 自动加载类
- php面向对象(OOP)—spl_autoload_register()注册自定义的自动加载函数
- PHP autoload机制详解 自动加载函数
- PHP autoload机制详解 自动加载函数
- php自动加载类 __autoload()函数
- php自动加载类 __autoload()函数
- php 自动加载类函数spl_autoload_register()
- 关于PHP中的自动加载函数 __autoload
- php项目中自动加载机制
- php中注册自动加载方法
- PHP中spl_autoload_register函数的用法(类的对象自动加载)
- 自动加载自定义类
- 12-31--PHP函数spl_autoload_register实现自动加载研究
- php命名空间与自动加载函数一起使用
- PHP使用__autoload()函数自动加载未定义的类
- Ext.form.field.ComboBox 切换store没有反应
- JBPM工程需要的第三方类库
- 熬之滴水穿石:JSP--HTML中的JAVA代码(9)
- java 反射
- Selenium 处理 modal 对话框(转)
- php中自定义自动加载函数
- 计算机科学中最重要的32个算法
- 招致创业失败的七个错误
- JSON学习笔记(格式/第三方库jsonCpp与libJson的配置和使用) cocos2d-x
- [Leetcode]Best Time to Buy and Sell Stock III
- hibernate 特殊情况下 属性找不到get方法的解决方案
- CF 196B(Psychos in a Line-单调队列贪心)
- 这次真的谈谈如何管理一流人才
- error RC1004: unexpected end of file found处理方法