Beispiel #1
0
 public static function loadClass()
 {
     $system = CoreLoader::$system;
     $methodInfo = self::parseURI();
     self::$info =& $methodInfo;
     // 在解析路由之后,就注册自动加载,这样控制器可以继承类库文件夹里面的自定义父控制器,实现hook功能,达到拓展控制器的功能
     // 但是plugin模式下,路由器不再使用,那么这里就不会被执行,自动加载功能会失效,所以在每个instance方法里面再尝试加载一次即可,
     // 如此一来就能满足两种模式
     CoreLoader::classAutoloadRegister();
     // var_dump($methodInfo);
     if (file_exists($methodInfo['file'])) {
         include $methodInfo['file'];
         CoreInput::$router = $methodInfo;
         if (!CoreInput::isCli()) {
             // session自定义配置检查,只在非命令行模式下启用
             self::checkSession();
         }
         $class = new $methodInfo['class']();
         if (method_exists($class, $methodInfo['method'])) {
             $methodInfo['parameters'] = is_array($methodInfo['parameters']) ? $methodInfo['parameters'] : array();
             $result = true;
             if (method_exists($class, '__before')) {
                 $class->__before();
             }
             if (method_exists($class, '__output')) {
                 ob_start();
                 $result = call_user_func_array(array($class, $methodInfo['method']), $methodInfo['parameters']);
                 if (method_exists($class, '__after')) {
                     $class->__after($result);
                 }
                 $buffer = ob_get_contents();
                 @ob_end_clean();
                 $class->__output($buffer);
             } else {
                 $result = call_user_func_array(array($class, $methodInfo['method']), $methodInfo['parameters']);
                 if (method_exists($class, '__after')) {
                     $class->__after($result);
                 }
             }
             $result = null;
         } else {
             Fn::trigger404($methodInfo['class'] . ':' . $methodInfo['method'] . ' not found.');
         }
     } else {
         if ($system['debug']) {
             Fn::trigger404('file:' . $methodInfo['file'] . ' not found.');
         } else {
             Fn::trigger404();
         }
     }
 }