/** * 构造函数 * * @param array $app_config * * 构造应用程序对象 */ protected function __construct(array $app_config) { // #IFDEF DEBUG global $g_boot_time; QLog::log('--- STARTUP TIME --- ' . $g_boot_time, QLog::DEBUG); // #ENDIF /** * 初始化运行环境 */ // 禁止 magic quotes set_magic_quotes_runtime(0); // 处理被 magic quotes 自动转义过的数据 if (get_magic_quotes_gpc()) { $in = array(&$_GET, &$_POST, &$_COOKIE, &$_REQUEST); while (list($k, $v) = each($in)) { foreach ($v as $key => $val) { if (!is_array($val)) { $in[$k][$key] = stripslashes($val); continue; } $in[] =& $in[$k][$key]; } } unset($in); } // 设置异常处理函数 set_exception_handler(array($this, 'exception_handler')); // 初始化应用程序设置 $this->_app_config = $app_config; $this->_initConfig(); Q::replaceIni('app_config', $app_config); // 设置默认的时区 date_default_timezone_set(Q::ini('l10n_default_timezone')); // 设置 session 服务 if (Q::ini('runtime_session_provider')) { Q::loadClass(Q::ini('runtime_session_provider')); } // 打开 session if (Q::ini('runtime_session_start')) { session_start(); // #IFDEF DEBUG QLog::log('session_start()', QLog::DEBUG); QLog::log('session_id: ' . session_id(), QLog::DEBUG); // #ENDIF } // 导入类搜索路径 Q::import($app_config['APP_DIR']); Q::import($app_config['APP_DIR'] . '/model'); Q::import($app_config['MODULE_DIR']); // 注册应用程序对象 Q::register($this, 'app'); }
/** * 第一步初始化 * * @param string $class */ protected function _init1($class) { // 从指定类获得初步的定义信息 Q::loadClass($class); $this->class_name = $class; $ref = (array) call_user_func(array($class, '__define')); // 设置 find_sql if (!empty($ref['find_sql'])) { $this->_find_sql = $ref['find_sql']; } else { throw new QDB_ActiveRecord_Exception('must set "find_sql".'); } if (!empty($ref['dsn'])) { $this->_dsn = $ref['dsn']; } // 根据字段定义确定字段属性 if (empty($ref['props']) || !is_array($ref['props'])) { $ref['props'] = array(); } foreach ($ref['props'] as $prop_name => $config) { $this->addProp($prop_name, $config); } // 绑定行为插件 if (isset($ref['behaviors'])) { $config = isset($ref['behaviors_settings']) ? $ref['behaviors_settings'] : array(); $this->bindBehaviors($ref['behaviors'], $config); } }
/** * 执行一个查询,返回一个查询对象或者 boolean 值,出错时抛出异常 * * $sql 是要执行的 SQL 语句字符串,而 $inputarr 则是提供给 SQL 语句中参数占位符需要的值。 * * 如果执行的查询是诸如 INSERT、DELETE、UPDATE 等不会返回结果集的操作, * 则 execute() 执行成功后会返回 true,失败时将抛出异常。 * * 如果执行的查询是 SELECT 等会返回结果集的操作, * 则 execute() 执行成功后会返回一个 DBO_Result 对象,失败时将抛出异常。 * * QDB_Result_Abstract 对象封装了查询结果句柄,而不是结果集。 * * @param string $sql * @param array $inputarr * * @return QDB_Result_Abstract */ function execute($sql, $inputarr = null) { if (is_array($inputarr)) { $sql = $this->_fakebind($sql, $inputarr); } if (!$this->_conn) { $this->connect(); } //print_R($sql); $this->_lastrs = @pg_query($this->_conn, $sql); if ($this->_log_enabled) { QLog::log($sql, QLog::DEBUG); } if (is_resource($this->_lastrs)) { Q::loadClass('Qdb_Result_Pgsql'); return new QDB_Result_Pgsql($this->_lastrs, $this->_fetch_mode); } elseif ($this->_lastrs) { $this->_last_err = null; $this->_last_err_code = null; return $this->_lastrs; } else { $this->_last_err = pg_errormessage($this->_conn); $this->_last_err_code = null; $this->_has_failed_query = true; throw new QDB_Exception($sql, $this->_last_err, $this->_last_err_code); } }
/** * 第一步初始化 * * @param string $class */ protected function _init1($class) { // 从指定类获得初步的定义信息 Q::loadClass($class); $this->class_name = $class; $ref = (array) call_user_func(array($class, '__define')); /** * 检查是否是继承 */ if (!empty($ref['inherit'])) { $this->inherit_base_class = $ref['inherit']; /** * 继承类的 __define() 方法只需要指定与父类不同的内容 */ $base_ref = (array) call_user_func(array($this->inherit_base_class, '__define')); $ref = array_merge_recursive($base_ref, $ref); } // 被继承的类 $this->inherit_type_field = !empty($ref['inherit_type_field']) ? $ref['inherit_type_field'] : null; // 设置表数据入口对象 $table_config = !empty($ref['table_config']) ? (array) $ref['table_config'] : array(); if (!empty($ref['table_class'])) { $this->table = $this->_tableByClass($ref['table_class'], $table_config); } else { $this->table = $this->_tableByName($ref['table_name'], $table_config); } $this->table_meta = $this->table->columns(); // 根据字段定义确定字段属性 if (empty($ref['props']) || !is_array($ref['props'])) { $ref['props'] = array(); } foreach ($ref['props'] as $prop_name => $config) { $this->addProp($prop_name, $config); } // 将没有指定的字段也设置为对象属性 foreach ($this->table_meta as $prop_name => $field) { if (isset($this->props2fields[$prop_name])) { continue; } $this->addProp($prop_name, $field); } // 设置其他选项 if (!empty($ref['create_reject'])) { $this->create_reject = array_flip(Q::normalize($ref['create_reject'])); } if (!empty($ref['update_reject'])) { $this->update_reject = array_flip(Q::normalize($ref['update_reject'])); } if (!empty($ref['create_autofill']) && is_array($ref['create_autofill'])) { $this->create_autofill = $ref['create_autofill']; } if (!empty($ref['update_autofill']) && is_array($ref['update_autofill'])) { $this->update_autofill = $ref['update_autofill']; } if (!empty($ref['attr_accessible'])) { $this->attr_accessible = array_flip(Q::normalize($ref['attr_accessible'])); } if (!empty($ref['attr_protected'])) { $this->attr_protected = array_flip(Q::normalize($ref['attr_protected'])); } // 准备验证规则 if (empty($ref['validations']) || !is_array($ref['validations'])) { $ref['validations'] = array(); } $this->validations = $this->_prepareValidationRules($ref['validations']); // 设置对象 ID 属性名 $pk = $this->table->getPK(); $this->idname = array(); foreach ($this->table->getPK() as $pk) { $pn = $this->fields2props[$pk]; $this->idname[$pn] = $pn; } $this->idname_count = count($this->idname); // 绑定行为插件 if (isset($ref['behaviors'])) { $config = isset($ref['behaviors_settings']) ? $ref['behaviors_settings'] : array(); $this->bindBehaviors($ref['behaviors'], $config); } }
/** * 测试载入类(大小写敏感) */ function testLoadClassWithCaseSensitive() { Q::loadClass('Class2'); }
<?php ///////////////////////////////////////////////////////////////////////////// // QeePHP Framework // // Copyright (c) 2005 - 2008 QeeYuan China Inc. (http://www.qeeyuan.com) // // 许可协议,请查看源代码中附带的 LICENSE.TXT 文件, // 或者访问 http://www.qeephp.org/ 获得详细信息。 ///////////////////////////////////////////////////////////////////////////// /** * 定义 Chili_Runner_Abstract 类 */ // {{ include Q::loadClass('Chili_Exception'); // }} /** * Chili_Runner_Abstract 是应用程序构造器的抽象类 * * @package chili */ abstract class Chili_Runner_Abstract { /** * 复制文件时要动态替换的内容 * * @var array */ private $content_search = array('%QEEPHP_INST_DIR%', '%APP_ID%'); private $content_replace = array(); /**
/** * QeePHP 应用程序 MVC 模式入口 * * @return mixed */ function run() { // #IFDEF DEBUG QLog::log(__METHOD__, QLog::DEBUG); // #ENDIF // 设置默认的时区 date_default_timezone_set($this->context->getIni('l10n_default_timezone')); // 设置 session 服务 if ($this->context->getIni('runtime_session_provider')) { Q::loadClass($this->context->getIni('runtime_session_provider')); } // 打开 session if ($this->context->getIni('runtime_session_start')) { // #IFDEF DEBUG QLog::log('session_start()', QLog::DEBUG); // #ENDIF session_start(); } // 设置验证失败错误处理的回调方法 $this->context->setIni('dispatcher_on_access_denied', array($this, 'onAccessDenied')); // 设置处理动作方法未找到错误的回调方法 $this->context->setIni('dispatcher_on_action_not_found', array($this, 'onActionNotFound')); // 从 session 中提取 flash message if (isset($_SESSION)) { $key = $this->context->getIni('app_flash_message_key'); $arr = isset($_SESSION[$key]) ? $_SESSION[$key] : null; if (!is_array($arr)) { $arr = array(self::FLASH_MSG_INFO, $arr); } elseif (!isset($arr[1])) { $arr = array(self::FLASH_MSG_INFO, $arr[0]); } if ($arr[0] != self::FLASH_MSG_ERROR && $arr[0] != self::FLASH_MSG_INFO && $arr[0] != self::FLASH_MSG_WARNING) { $arr[0] = self::FLASH_MSG_INFO; } $this->_flash_message_type = $arr[0]; $this->_flash_message = $arr[1]; unset($_SESSION[$key]); } // 初始化访问控制对象 $this->acl = Q::getSingleton('QACL'); // 执行动作 $context = QContext::instance($this->context->module_name, $this->_appid); return $this->_executeAction($context); }