Esempio n. 1
0
 public static function run($app = NULL, $do = NULL, $args = NULL, $prefix = "do_")
 {
     //empty($app) && $app   = $_GET['app']; //单一入口
     if (empty($app)) {
         $fi = iFS::name(__SELF__);
         $app = $fi['name'];
     }
     if (!in_array($app, self::$apps) && iPHP_DEBUG) {
         iPHP::throw404('运行出错!找不到应用程序: <b>' . $app . '</b>', '0001');
     }
     self::$app_path = iPHP_APP_DIR . '/' . $app;
     self::$app_file = self::$app_path . '/' . $app . '.app.php';
     is_file(self::$app_file) or iPHP::throw404('运行出错!找不到文件: <b>' . $app . '.app.php</b>', '0002');
     if ($do === NULL) {
         $do = iPHP_APP;
         $_GET['do'] && ($do = iS::escapeStr($_GET['do']));
     }
     if ($_POST['action']) {
         $do = iS::escapeStr($_POST['action']);
         $prefix = 'ACTION_';
     }
     self::$app_name = $app;
     self::$app_do = $do;
     self::$app_method = $prefix . $do;
     self::$app_tpl = iPHP_APP_DIR . '/' . $app . '/template';
     self::$app_vars = array("MOBILE" => iPHP::$mobile, 'COOKIE_PRE' => iPHP_COOKIE_PRE, 'REFER' => __REF__, 'CONFIG' => self::$config, "APP" => array('NAME' => self::$app_name, 'DO' => self::$app_do, 'METHOD' => self::$app_method));
     iPHP::$iTPL->_iTPL_VARS['SAPI'] .= self::$app_name;
     iPHP::$iTPL->_iTPL_VARS += self::$app_vars;
     self::$app = iPHP::app($app);
     if (self::$app_do && self::$app->methods) {
         in_array(self::$app_do, self::$app->methods) or iPHP::throw404('运行出错! <b>' . self::$app_name . '</b> 类中找不到方法定义: <b>' . self::$app_method . '</b>', '0003');
         $method = self::$app_method;
         $args === null && ($args = self::$app_args);
         if ($args) {
             if ($args === 'object') {
                 return self::$app;
             }
             return call_user_func_array(array(self::$app, $method), (array) $args);
         } else {
             method_exists(self::$app, self::$app_method) or iPHP::throw404('运行出错! <b>' . self::$app_name . '</b> 类中 <b>' . self::$app_method . '</b> 方法不存在', '0004');
             return self::$app->{$method}();
         }
     } else {
         iPHP::throw404('运行出错! <b>' . self::$app_name . '</b> 类中 <b>' . self::$app_method . '</b> 方法不存在', '0005');
     }
 }