Exemplo n.º 1
0
 private static function action()
 {
     //禁止使用模块检测
     if (in_array(MODULE, C('http.deny_module'))) {
         throw new Exception("模块禁止访问");
     }
     $class = 'app\\' . MODULE . '\\controller\\' . CONTROLLER;
     //控制器不存在
     if (!class_exists($class)) {
         throw new Exception("{$class} 不存在");
     }
     $controller = Route::$app->make($class, TRUE);
     //执行控制器中间件
     \Middleware::performControllerMiddleware();
     //执行动作
     try {
         $reflection = new ReflectionMethod($controller, ACTION);
         if ($reflection->isPublic()) {
             //执行动作
             if ($result = call_user_func_array([$controller, ACTION], self::$routeArgs)) {
                 if (IS_AJAX && is_array($result)) {
                     ajax($result);
                 } else {
                     echo $result;
                 }
             }
         } else {
             throw new ReflectionException('请求地址不存在');
         }
     } catch (ReflectionException $e) {
         $action = new ReflectionMethod($controller, '__call');
         $action->invokeArgs($controller, [ACTION, '']);
     }
 }