您的位置:首页 > 编程语言 > PHP开发

zhphp framework (五) 框架加载类

2015-12-11 13:23 585 查看
<?php
/**
* Created by PhpStorm.
* User:  张华
* Date: 2015/8/27
* Time: 1:12
* * QQ: 746502560@qq.com
* To change this template use File | Settings | File Templates.
*/
defined('IN_ZHPHP')?NULL:die('attempts to hack the system');
if(function_exists('spl_autoload_register')){
spl_autoload_register(array('loader', 'autoload'));
} else {
function __autoload($className) {
return loader::autoload($className);
}
}
final class loader {
private function __construct() {}#防止被实例化
public  static  function  init(){
$files=self::loadSysConf();
$includePath=implode(PATH_SEPARATOR,$files);
set_include_path($includePath.PATH_SEPARATOR.get_include_path());
}
public  static  function  autoload($className){
if(class_exists($className)  === false){
//解决smarty 自动加载冲突
if(preg_match('/Smarty/i',$className)){
return;
}
$file=$className.'.class.php';
include_once  $file;
}
}
private  static  function  loadSysConf(){
$_src=array(
ROOT_PATH.'core/',
ROOT_PATH.'engine/',
ROOT_PATH.'engine/factory/',
ROOT_PATH.'library/',
ROOT_PATH.'extends/Tpl/Smarty/',
APP_PATH.'models/',
APP_PATH.'controllers/',
APP_PATH.'controllers/components/',
APP_PATH.'widget/',
APP_PATH.'modules/'
);
return $_src;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: