Core.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace KIF\Core;
  3. use Exception;
  4. const VERSION = '0.0.1';
  5. const AUTHOR = 'gaoxiaogang@gmail.com';
  6. class Core {
  7. static public function autoload($class_name) {
  8. // var_dump($class_name);
  9. $class_name = str_replace('/', '', $class_name);
  10. $class_name = str_replace('.', '', $class_name);
  11. $class_name = str_replace('\\', '/', $class_name);
  12. $tmp_ds_pos = strpos($class_name, '/');
  13. if ($tmp_ds_pos !== false) {
  14. $root_namespace = substr($class_name, 0, $tmp_ds_pos);
  15. $class_name = substr($class_name, $tmp_ds_pos+1);
  16. } else {
  17. $root_namespace = '';
  18. }
  19. # 当前app的库路径
  20. if ($root_namespace) {
  21. if ($root_namespace == 'KIF') {
  22. $class_path = KIF_PATH . DS . $class_name . '.class.php';
  23. } else {
  24. try {# 框架一定会先加载KIF命名空间下的类,所以到这里Config肯定已被外部app初始化了
  25. $allConfigs = Config::all();
  26. foreach ($allConfigs as $config) {
  27. if ($config['Namespace'] == $root_namespace) {
  28. $app_lib_path = $config['Lib_Path'];
  29. $class_path = $app_lib_path . DS . $class_name . '.class.php';
  30. break;
  31. }
  32. }
  33. } catch (Exception $e) {
  34. // do nothing
  35. }
  36. }
  37. if (file_exists($class_path)) {
  38. return require_once($class_path);
  39. }
  40. } else {
  41. $class_path = KIF_PATH . DS . $class_name . '.class.php';
  42. if (file_exists($class_path)) {
  43. return require_once($class_path);
  44. } else {
  45. $app_lib_path = Config::getInstance()->get('Lib_Path');
  46. $class_path = $app_lib_path . DS . $class_name . '.class.php';
  47. if (file_exists($class_path)) {
  48. return require_once($class_path);
  49. }
  50. }
  51. }
  52. }
  53. }