Пример #1
0
 /**
  * 构造函数
  *
  */
 public function __construct()
 {
     // APP配置
     $appCfg = QP_Sys::getAppCfg();
     $this->_urlMethod = $appCfg['url_method'];
     $this->_request = QP_Request::getInstance();
 }
Пример #2
0
 /**
  * 应用程序初始化
  *
  */
 private function _initApp()
 {
     // 得到APP配置
     $appCfg = QP_Sys::getAppCfg();
     // 设置时区
     date_default_timezone_set($appCfg['timezone']);
 }
Пример #3
0
 /**
  * 得到数据库操作对象
  *
  * @param string $driverType 驱动类型,可选项有: 'mysql' | 'mysqli' | 'pdo'
  * @param string $configItem 数据库配置项,具体请看 Application/Configs/Database.php
  * @return object
  */
 public static function factory($driverType = 'mysql', $configItem = 'default')
 {
     // 对象唯一KEY
     $key = $driverType . $configItem;
     // 判断驱动是否已经生成对应的对象了
     $driverType = ucfirst(strtolower($driverType));
     if (!isset(self::$_instance[$key])) {
         // 判断驱动文件是否存在
         $driverFile = QUICKPHP_PATH . '/Db/' . $driverType . '.php';
         if (!file_exists($driverFile)) {
             throw new QP_Exception('数据驱动文件不存在:' . $driverFile);
         }
         // 判断配置项是否定义
         $dfCfgFile = APPLICATION_PATH . '/Configs/Database.php';
         $dbConfig = (include $dfCfgFile);
         if (!isset($dbConfig[$configItem])) {
             throw new QP_Exception("数据库配置项:{$configItem} 在配置文件中找不到:{$dfCfgFile}");
         }
         // 得到APP配置
         $appCfg = QP_Sys::getAppCfg();
         // 生成驱动对象
         require $driverFile;
         $class = 'QP_Db_' . $driverType;
         self::$_instance[$key] = new $class($dbConfig[$configItem], $appCfg['debug'], $appCfg['display_error']);
     }
     return self::$_instance[$key];
 }
Пример #4
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());
    }
Пример #5
0
 /**
  * 构造函数,但该类不能被实例化
  */
 private function __construct()
 {
     // 处理请求数据
     $_POST = $this->_magicQuotes($_POST);
     $_GET = $this->_magicQuotes($_GET);
     $_REQUEST = $this->_magicQuotes($_REQUEST);
     // 如果 URL模式 不是 standard 则要解析 URI
     $appCfg = QP_Sys::getAppCfg();
     if ($appCfg['url_method'] != 'standard') {
         $this->_parseUri();
     }
 }
Пример #6
0
 /**
  * 构造函数
  *
  */
 public function __construct()
 {
     $this->_request = QP_Request::getInstance();
     $this->_appConfig = QP_Sys::getAppCfg();
 }
Пример #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];
 }
Пример #8
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);
            }
        }
    }