Exemple #1
0
 /**
  * 构造函数
  *
  */
 public function __construct()
 {
     // APP配置
     $appCfg = QP_Sys::getAppCfg();
     $this->_urlMethod = $appCfg['url_method'];
     $this->_request = QP_Request::getInstance();
 }
Exemple #2
0
 /**
  * 生成单个实例
  *
  * @return Request object
  */
 public static function getInstance()
 {
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
Exemple #3
0
    /**
     * 构造函数
     *
     * @param string $viewBasePath 视图文件的根目录,为空时默认为:"Application/Views/Script/"
     */
    public function __construct($viewBasePath = null)
    {
        // 初始化模板根目录
        parent::__construct($viewBasePath);
        // APP配置
        $appCfg = QP_Sys::getAppCfg();
        // 是否安装了 SMARTY 库文件
        $smartyFile = QUICKPHP_PATH . '/Smarty/Smarty/Smarty.class.php';
        if (!file_exists($smartyFile)) {
            throw new QP_Exception('<hr/>
			请到 <a href="http://http://www.smarty.net/download" target="_blank">Smarty 官网</a>
			或到 <a href="http://www.vquickphp.com" target="_blank">QuickPHP 官网</a>
			下载 Smarty 放到 QuickPHP/Smarty/Smarty 目录下 <br/>
			注意:<font color="red">只支持 Smarty 2 Releases 的版本</font>(足够用啦,Smarty 3.x 没研究过它^_^)
			<hr/>');
        }
        // 创建 SMARTY 对象
        require_once $smartyFile;
        $this->_smarty = new Smarty();
        // 左/右 标记定义
        $this->_smarty->left_delimiter = self::LEFT_DELIMITER;
        $this->_smarty->right_delimiter = self::RIGHT_DELIMITER;
        // 编译文件目录
        $this->_smarty->compile_dir = APPLICATION_PATH . '/Data/Temp';
        // 是否强行编译
        $this->_smarty->force_compile = $appCfg['debug'];
        // 赋于视图中全局的对象
        $this->_smarty->assign('request', QP_Request::getInstance());
    }
Exemple #4
0
 /**
  * 检测用户的权限
  *
  */
 private function _checkpriv()
 {
     $controller = isset($_GET['c']) ? $_GET['c'] : QP_Controller::DEFAULT_CONTROLLER;
     $action = isset($_GET['a']) ? $_GET['a'] : QP_Controller::DEFAULT_ACTION;
     // 如果有权限则返回
     $ret = Priv::check(QP_Session_Session::get('login_userid'), $controller, $action);
     if ($ret) {
         return;
     }
     // 如果是异步访问则直接输出错误
     if (QP_Request::getInstance()->isAJAX()) {
         die('Priv Access denied');
     } else {
         // 其它方式则直接提示后跳转
         QP_Sys::msgbox('Priv Access denied!', url('index', 'index'), 10);
     }
 }
Exemple #5
0
/**
 * 根据KEY返回对应语言
 *
 * @param string $item : 如果没有指定控制器则用当前的控制器,如:'index.tabtitle' == 'tabtitle'
 * @param array $vars :替换的内容
 */
function L($item, $vars = array())
{
    // 分解控制器和方法和KEY
    if (strpos($item, '.') === false) {
        $request = QP_Request::getInstance();
        $get = $request->getGet();
        $parsm = $request->getParam();
        $controller = strtolower($get['controller'] ? $get['controller'] : $parsm['controller']);
        $key = $item;
    } else {
        list($controller, $key) = explode('.', $item);
    }
    // 得到语言包
    static $langArr = array();
    if (!isset($langArr[$controller])) {
        $lang = getLang();
        $langArr[$controller] = (include APPLICATION_PATH . '/Lang/' . $lang . '/' . ucfirst($controller) . '.php');
    }
    // 如果有对应的语言设置
    if (isset($langArr[$controller][$key])) {
        $text = $langArr[$controller][$key];
        // 是否要进行替换
        if ($vars) {
            foreach ($vars as $k => $v) {
                $rk = $k + 1;
                $text = str_replace('\\' . $rk, $v, $text);
            }
        }
    } else {
        $text = $key;
    }
    return $text;
}
Exemple #6
0
 /**
  * 构造函数
  *
  */
 public function __construct()
 {
     $this->_request = QP_Request::getInstance();
     $this->_appConfig = QP_Sys::getAppCfg();
 }
Exemple #7
0
 /**
  * 视图助手,助手都定义在 Application/Views/Helpers
  *
  * @param string $name 助手名,默认情况下为当前控制器所对应的
  * @return object
  */
 public function helper($name = '')
 {
     // 默认为当前控制器所对应的助手
     if ($name == '') {
         // 根据不同的URL模式得到当前的控制器
         $request = QP_Request::getInstance();
         $appConfig = QP_Sys::getAppCfg();
         $param = $appConfig['url_method'] == 'standard' ? $request->getGet() : $request->getParam();
         $name = $param['controller'];
     }
     // 得到助手文件名
     $name = ucfirst(strtolower($name));
     // 如果是新的助手对象已生成则要生成它
     if (!isset(self::$_helper[$name]) || !is_object(self::$_helper[$name])) {
         // 助手文件不存在
         $helperFile = APPLICATION_PATH . '/Views/Helpers/' . $name . '.php';
         if (!file_exists($helperFile)) {
             throw new QP_Exception("助手文件不存在:{$helperFile}", QP_Exception::EXCEPTION_NO_HELPER);
         }
         // 包含助手生成对象
         require_once $helperFile;
         $className = 'Helper_' . $name;
         // 类是否存在的
         if (!class_exists($className, false)) {
             throw new QP_Exception("类:{$className} 未定义在:{$helperFile}");
         }
         // 判断助手是否继承基类
         self::$_helper[$name] = new $className();
         if (!self::$_helper[$name] instanceof QP_View_Helper) {
             throw new QP_Exception("助手类 {$className} 必需继承 QP_View_Helper 基类");
         }
         $obj = self::$_helper[$name];
         self::$_helper[$name]->init();
     }
     return self::$_helper[$name];
 }
Exemple #8
0
</span> SQL:<span class="tblue"><?php 
    echo $row['sql'];
    ?>
</span> <br/>
    <?php 
}
?>
    </td>
  </tr>

  <tr class="tr_click" onclick="qp_debug_swap_show('qp_tr_param')">
    <td colspan="2">[URI PARAM]</td>
  </tr>
  <tr style="display:none" id="qp_tr_param">
    <td colspan="2"><?php 
$params = QP_Request::getInstance()->getParam();
if ($params) {
    qp_sys::dump($params);
}
?>
</td>
  </tr>

  <tr class="tr_click" onclick="qp_debug_swap_show('qp_tr_get')">
    <td colspan="2">[GET]</td>
  </tr>
  <tr style="display:none" id="qp_tr_get">
    <td colspan="2"><?php 
if (isset($_GET) && $_GET) {
    qp_sys::dump($_GET);
}
Exemple #9
0
 /**
  * 返回匹配 URI 的路路由配置,这个方法框架会调用
  *
  * @param str $uri
  */
 public static function matches($uri)
 {
     // 得到所有设置的路由URI
     $regexUri = array();
     foreach (self::$_router as $name => $param) {
         // 如果没有设置 bind 字段
         if (!isset($param['bind'])) {
             $regexUri[$name] = $param['uri'];
             continue;
         }
         // 将 uri 和 bind 合并
         $search = $replace = array();
         foreach ($param['bind'] as $key => $value) {
             $search[] = '<' . $key . '>';
             $replace[] = $value;
         }
         $regexUri[$name] = str_replace($search, $replace, $param['uri']);
     }
     // 遍历 URI 匹配,找到第一个即认为找到了
     foreach ($regexUri as $name => $regUri) {
         // 合并成正则表达式
         $regUri = '/' . str_replace('/', "\\/", $regUri) . '/';
         // 匹配
         $bool = preg_match($regUri, $uri, $match);
         // 如果没有找到则直接下一个继续
         if (!$bool) {
             continue;
         }
         // 如果找到了则就返回找到的第一个配置
         // print_r($match);
         // 得到匹配成功的配置
         $router = self::$_router[$name];
         // 如果没有搜索到子项则直接返回
         if (count($match) == 1) {
             return $router;
         }
         // 搜索到了则要 设置 Request 的 param()
         $param = array();
         $i = 0;
         $keyArr = array_keys($router['bind']);
         foreach ($keyArr as $key) {
             ++$i;
             $param[$key] = isset($match[$i]) ? $match[$i] : '';
         }
         // print_r($param);
         QP_Request::getInstance()->setParam($param);
         // 走了,其它配置不管了
         return $router;
     }
     return array();
 }
Exemple #10
0
 /**
  * 控制器初始化
  *
  */
 public function __construct()
 {
     $this->request = QP_Request::getInstance();
 }
Exemple #11
0
    /**
     * 检测当前是否以 PHP CLI 方式运行,框架初始化时自动调用
     */
    public static function _checkSapi()
    {
        // 不是则直接闪人
        if (PHP_SAPI != 'cli') {
            return;
        }
        // 根据框架的配置将 $_SERVER['argv'] 变量的值转成 REQUEST 的 GET 或 PARAM 值
        $request = QP_Request::getInstance();
        // APP的配置
        $appCfg = QP_Sys::getAppCfg();
        $argv = $request->server('argv');
        // 主程序文件名
        $prgName = $argv[0];
        unset($argv[0]);
        // URL模式为 standard 时的 GET KEY名映射
        $getKeyMap = array('controller' => QP_Request::C, 'action' => QP_Request::A);
        // 设置所有参数
        foreach ($argv as $arg) {
            $arr = explode('=', $arg);
            if (count($arr) != 2) {
                echo <<<EOF
\t\t\t\tsyntax:
\t\t\t\tphp {$prgName} [controller=<controller> action=<action> param1=value1 param2=value2 ...]

\t\t\t\texamples:
\t\t\t\tphp {$prgName} controller=index action=test id=10 name=vg

EOF;
                exit;
            }
            // 先设置控制器和动作
            list($key, $val) = $arr;
            if ($appCfg['url_method'] == 'standard') {
                if (array_key_exists($key, $getKeyMap)) {
                    $key = $getKeyMap[$key];
                }
                $request->setGet($key, $val);
            } else {
                $request->setParam($key, $val);
            }
        }
    }