1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- <?php
- namespace KIF\Core;
- use Exception;
- const VERSION = '0.0.1';
- const AUTHOR = 'gaoxiaogang@gmail.com';
- class Core {
- static public function autoload($class_name) {
- // var_dump($class_name);
-
- $class_name = str_replace('/', '', $class_name);
- $class_name = str_replace('.', '', $class_name);
-
- $class_name = str_replace('\\', '/', $class_name);
- $tmp_ds_pos = strpos($class_name, '/');
- if ($tmp_ds_pos !== false) {
- $root_namespace = substr($class_name, 0, $tmp_ds_pos);
- $class_name = substr($class_name, $tmp_ds_pos+1);
- } else {
- $root_namespace = '';
- }
- # 当前app的库路径
- if ($root_namespace) {
- if ($root_namespace == 'KIF') {
- $class_path = KIF_PATH . DS . $class_name . '.class.php';
- } else {
- try {# 框架一定会先加载KIF命名空间下的类,所以到这里Config肯定已被外部app初始化了
- $allConfigs = Config::all();
- foreach ($allConfigs as $config) {
- if ($config['Namespace'] == $root_namespace) {
- $app_lib_path = $config['Lib_Path'];
- $class_path = $app_lib_path . DS . $class_name . '.class.php';
-
- break;
- }
- }
- } catch (Exception $e) {
- // do nothing
- }
- }
- if (file_exists($class_path)) {
- return require_once($class_path);
- }
- } else {
- $class_path = KIF_PATH . DS . $class_name . '.class.php';
- if (file_exists($class_path)) {
- return require_once($class_path);
- } else {
- $app_lib_path = Config::getInstance()->get('Lib_Path');
- $class_path = $app_lib_path . DS . $class_name . '.class.php';
- if (file_exists($class_path)) {
- return require_once($class_path);
- }
- }
- }
- }
- }
|