/** * 自动加载函数 * * @param string $class 类名 * 加载 Controller/middleware */ public static function autoload_middleware($class) { $classpath = bus('root') . 'Controller/Middleware/'; $class = str_replace('Controller\\Middleware\\', '', $class); $classfile = $classpath . $class . '.php'; //首先检查在应用目录中是否存在该类,存在加载,不存在,则到根下寻找 includeIfExist($classfile); }
public function handle($request, \Closure $next) { //建立中间件 & 行为 //根据路由执行系列操作 $basepath = sc('Router')['m'] ? rtrim(APPROOT, '/') . '/Modules/' . sc('Modulelist')[sc('Router')['m']] . '/' : rtrim(APPROOT, '/') . '/'; //|----------------------------------------------- $controller = '\\Controller\\' . sc('Router')['c']; $action = sc('Router')['action']; $params = sc('Router')['param']; if (sc('Router')['m']) { $basepath = rtrim(APPROOT, '/') . '/Modules/' . sc('Modulelist')[sc('Router')['m']] . '/Controller/'; } else { $basepath = rtrim(APPROOT, '/') . '/' . 'Controller/'; } $basecontrollerpath = $basepath . 'BaseController.php'; $controllerextpath = $basepath . sc('Router')['c'] . '.' . sc('Router')['a'] . '.php'; $controllerpath = $basepath . sc('Router')['c'] . '.php'; //加载基类 - 如果基类存在,则加载 includeIfExist($basecontrollerpath); //尝试扩展控制器 - 尝试控制器 includeIfExist($controllerextpath); if (!class_exists($controller)) { includeIfExist($controllerpath); } //-------------------------------------------------------- if (!class_exists($controller)) { //控制器还没有找到,则报错 //404 bus('e', ['msg' => '404 controller miss']); geter('e.e404'); // echo $controller.'404 controller miss'; } //实例化 bus('controller', new $controller()); //这里已经正常了 bus('middlewareBefore', bus('controller')->middlewareBefore()); bus('middlewareAfter', bus('controller')->middlewareAfter()); bus('behavior', bus('controller')->behaviors()); //寻找扩展方法 if (!method_exists(bus('controller'), $action)) { bus('e', ['msg' => '404 method miss']); geter('e.e404'); // echo $action.'404 method miss'; } // Perform action return $next($request); }
/** * 自动加载函数 * @param string $class 类名 */ public static function autoload($class) { if (substr($class, -6) == 'Widget') { includeIfExist(C('APP_FULL_PATH') . '/Widget/' . $class . '.class.php'); } else { //首先检查在应用目录中是否存在该类,存在加载,不存在,则到根下寻找 includeIfExist(C('APP_FULL_PATH') . '/Lib/' . $class . '.class.php'); if (!class_exists($class)) { includeIfExist(C('BASE_FULL_PATH') . '/Lib/' . $class . '.class.php'); } if (!class_exists($class)) { includeIfExist(C('APP_FULL_PATH') . '/Models/' . $class . '.model.php'); } if (!class_exists($class)) { includeIfExist(C('BASE_FULL_PATH') . '/Models/' . $class . '.model.php'); } } }
public function E500() { $file = bus('root') . bus('app')['error_page_500']; includeIfExist($file); exit; }
/** * @param $class * 模型 */ public static function autoload_controller($class) { $router = C('Router'); //回溯地址 $hspath = C('app')['APP_PATH']; //控制器地址 if ($router['method_modules']) { $basepath = C('app')['APP_PATH'] . 'Modules/' . C('app')['modulelist'][$router['method_modules']] . '/'; } else { $basepath = $hspath; } if (substr($class, -6) == 'Widget') { includeIfExist($basepath . '/Widget/' . $class . '.class.php'); } else { //首先检查在应用目录中是否存在该类,存在加载,不存在,则到根下寻找 includeIfExist($basepath . '/Lib/' . $class . '.class.php'); if (!class_exists($class)) { includeIfExist($hspath . '/Lib/' . $class . '.class.php'); } if (!class_exists($class)) { includeIfExist($basepath . '/Models/' . $class . '.model.php'); } if (!class_exists($class)) { includeIfExist($hspath . '/Models/' . $class . '.model.php'); } } }
/** * 自动加载函数 * @param string $class 类名 */ public static function autoload($class) { if (substr($class, -10) == 'Controller') { includeIfExist(C('APP_FULL_PATH') . '/Controller/' . $class . '.class.php'); } elseif (substr($class, -6) == 'Widget') { includeIfExist(C('APP_FULL_PATH') . '/Widget/' . $class . '.class.php'); } else { includeIfExist(C('APP_FULL_PATH') . '/Lib/' . $class . '.class.php'); } }