Exemple #1
0
 /**
  * 运行应用程序
  * @param string $app 应用程序名称
  * @param string $do 动作名称
  * @return iCMS
  */
 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('VERSION' => iCMS_VER, "MOBILE" => iPHP::$mobile, 'API' => iCMS_API, 'UI' => iCMS_UI, 'UI_URL' => iCMS_UI_URL, 'SAPI' => iCMS_API . '?app=' . self::$app_name, 'COOKIE_PRE' => iPHP_COOKIE_PRE, 'REFER' => __REF__, 'CONFIG' => self::$config, "APP" => array('NAME' => self::$app_name, 'DO' => self::$app_do, 'METHOD' => self::$app_method), "APPID" => array('ARTICLE' => iCMS_APP_ARTICLE, 'CATEGORY' => iCMS_APP_CATEGORY, 'TAG' => iCMS_APP_TAG, 'PUSH' => iCMS_APP_PUSH, 'COMMENT' => iCMS_APP_COMMENT, 'PROP' => ICMS_APP_PROP, 'MESSAGE' => iCMS_APP_MESSAGE, 'FAVORITE' => iCMS_APP_FAVORITE, 'USER' => iCMS_APP_USER));
     define('iCMS_API_URL', iCMS_API . '?app=' . 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');
     }
 }