Exemple #1
0
/** gClass  类实例化函数  自动载入类定义文件,实例化并返回对象句柄
 *
 * @param class_name    类名称
 * @param args   类初始化时使用的参数,数组形式
 * @param sdir 载入类定义文件的路径,可以是目录+文件名的方式,也可以单独是目录。sdir的值将传入import()进行载入
 * @param force_inst 是否强制重新实例化对象
 */
function gClass($class_name, $args = null, $sdir = null, $force_inst = FALSE)
{
    // 检查类名称是否正确,以保证类定义文件载入的安全性
    if (preg_match('/[^a-z0-9\\-_.]/i', $class_name)) {
        gError($class_name . "类名称错误,请检查。");
    }
    // 检查是否该类已经实例化,直接返回已实例对象,避免再次实例化
    if (TRUE != $force_inst) {
        if (isset($GLOBALS['G']["inst_class"][$class_name])) {
            return $GLOBALS['G']["inst_class"][$class_name];
        }
    }
    // 如果$sdir不能读取,则测试是否仅路径
    if (null != $sdir && !gImport($sdir) && !gImport($sdir . "/{$class_name}.php")) {
        return FALSE;
    }
    $has_define = FALSE;
    // 检查类定义是否存在
    if (class_exists($class_name, false) || interface_exists($class_name, false)) {
        $has_define = TRUE;
    } else {
        if (TRUE == gImport($class_name . '.php')) {
            $has_define = TRUE;
        }
    }
    if (FALSE != $has_define) {
        $argString = '';
        $comma = '';
        if (null != $args) {
            for ($i = 0; $i < count($args); $i++) {
                $argString .= $comma . "\$args[{$i}]";
                $comma = ', ';
            }
        }
        eval("\$GLOBALS['G']['inst_class'][\$class_name]= new \$class_name({$argString});");
        return $GLOBALS['G']["inst_class"][$class_name];
    }
    gError($class_name . "类定义不存在,请检查。");
}
Exemple #2
0
<?php

defined('SITE_PATH') or exit('SET_ERROR');
// 载入系统常量定义
define('G_PATH', __DIR__);
require G_PATH . "/gDefine.php";
// 载入核心函数库
require G_PATH . "/gFunctions.php";
//note 判断服务器类型(test,develop,product)
gLoadServer();
//note 根据服务器类型加载配置文件
include SITE_PATH . "/include/config_" . QIHOOTYPE . ".php";
// 载入配置文件
empty($gConfig) && ($gConfig = null);
$GLOBALS['G'] = gConfigReady(require G_PATH . "/gConfig.php", $gConfig);
if (strtolower($GLOBALS['G']['mode']) == 'debug') {
    define('DEBUG', TRUE);
} else {
    define('DEBUG', FALSE);
}
// 自动开启SESSION
if ($GLOBALS['G']['auto_session']) {
    @session_start();
}
gImport(G_CORE . "/gArgs.php", FALSE, TRUE);
// 载入核心MVC架构文件
gImport(G_CORE . "/gController.php", FALSE, TRUE);
gImport(G_CORE . "/gModel.php", FALSE, TRUE);
gImport(G_CORE . "/gView.php", FALSE, TRUE);
empty($_SERVER['REQUEST_URI']) && ($_SERVER['REQUEST_URI'] = '');
gParseURL(htmlspecialchars($_SERVER['REQUEST_URI']));