AutoLoad.Class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Mall\Framework\Core;
  3. class AutoLoad
  4. {
  5. static function _autoLoad($class)
  6. {
  7. //var_dump($class);
  8. //xssCheck();
  9. if(function_exists('apcu_fetch') && ini_get('apc.enabled')){
  10. if ($file_path = apcu_fetch('autoload_'.PROJECT_DOMAIN.$class)) {
  11. loadFile($file_path);
  12. return true;
  13. }
  14. }
  15. $class_path = str_replace('\\', '/', $class) . '.Class.php';
  16. // util工具类特殊处理
  17. if(strpos($class_path, 'Util') === 0){
  18. $real_path = DS.$class_path;
  19. }else{
  20. $real_path = substr($class_path, strpos($class_path, '/'));
  21. }
  22. switch($real_path){
  23. case strpos($class_path, FRAMEWORK_NAME.'/') !== FALSE:
  24. $file_path = ROOT_PATH . $real_path;
  25. break;
  26. case strpos($class_path, 'Smarty') !== FALSE:
  27. return false;
  28. break;
  29. case strpos($class_path, 'Service') !== FALSE:
  30. if(!defined('SWOOLESERVER_NAME')){
  31. throw new \Exception('请去swoole服务项目启动脚本配置服务目录名称,重启生效!!!');
  32. }
  33. $file_path = ROOT_PATH . DS . '..' . DS . SWOOLESERVER_NAME . $real_path;
  34. break;
  35. default:
  36. $file_path = PROJECT_PATH . $real_path;
  37. }
  38. if(function_exists('apcu_fetch') && ini_get('apc.enabled')){
  39. apcu_add('autoload_'.PROJECT_DOMAIN.$class, $file_path);
  40. }
  41. loadFile($file_path);
  42. }
  43. }