Esempio n. 1
0
 /**
  * 执行指定的动作
  *
  * @return mixed
  */
 function execute($action_name, array $args = array())
 {
     $action_method = "action{$action_name}";
     // 执行指定的动作方法
     $this->_before_execute();
     #IFDEF DBEUG
     QLog::log('EXECUTE ACTION: ' . get_class($this) . '::' . $action_method . '()', QLog::DEBUG);
     #ENDIF
     $this->_view['_MSG'] = $this->_app->getFlashMessage();
     Q::replaceIni('OrderAvailable', true);
     Q::replaceIni('isAdmin', false);
     #dump(Q::ini('appini/managers'));
     if ($this->_user) {
         if (in_array($this->_user->user_mail, Q::ini('appini/managers'))) {
             Q::replaceIni('isAdmin', true);
         }
     }
     $this->_view['_UDI'] = QContext::instance()->requestUDI(false);
     $response = call_user_func_array(array($this, $action_method), $args);
     $this->_after_execute($response);
     if (is_null($response) && is_array($this->_view)) {
         // 如果动作没有返回值,并且 $this->view 不为 null,
         // 则假定动作要通过 $this->view 输出数据
         $config = array('view_dir' => $this->_getViewDir());
         $response = new $this->_view_class($config);
         $response->setViewname($this->_getViewName())->assign($this->_view);
         #dump($response);
         $this->_before_render($response);
     } elseif ($response instanceof $this->_view_class) {
         $response->assign($this->_view);
         $this->_before_render($response);
     }
     #dump($response);
     return $response;
 }
Esempio n. 2
0
 /**
  * 构造函数
  *
  * @param array $managed_app_config
  * @param array $managed_app_ini
  *
  * 构造应用程序对象
  */
 protected function __construct(array $managed_app_config, array $managed_app_ini)
 {
     set_exception_handler(array($this, 'exception_handler'));
     $dir = dirname(__FILE__);
     Q::import($dir . '/app');
     Q::import($dir . '/app/model');
     Q::import($managed_app_config['QEEPHP_DIR'] . '/extended');
     Q::replaceIni('managed_app_config', $managed_app_config);
     Q::replaceIni('managed_app_ini', $managed_app_ini);
 }
Esempio n. 3
0
 /**
  * 初始化应用程序设置
  */
 protected function _initConfig()
 {
     #IFDEF DEBUG
     QLog::log(__METHOD__, QLog::DEBUG);
     #ENDIF
     // 载入配置文件
     if ($this->_app_config['CONFIG_CACHED']) {
         /**
          * 从缓存载入配置文件内容
          */
         // 构造缓存服务对象
         $backend = $this->_app_config['CONFIG_CACHE_BACKEND'];
         $settings = isset($this->_app_config['CONFIG_CACHE_SETTINGS'][$backend]) ? $this->_app_config['CONFIG_CACHE_SETTINGS'][$backend] : null;
         $cache = new $backend($settings);
         // 载入缓存内容
         $cache_id = $this->_app_config['APPID'] . '_app_config';
         $config = $cache->get($cache_id);
         if (!empty($config)) {
             Q::replaceIni($config);
             return;
         }
     }
     // 没有使用缓存,或缓存数据失效
     $config = self::loadConfigFiles($this->_app_config);
     if ($this->_app_config['CONFIG_CACHED']) {
         $cache->set($cache_id, $config);
     }
     Q::replaceIni($config);
 }
Esempio n. 4
0
/**
 * 单元测试公用初始化文件
 */
date_default_timezone_set('Asia/Shanghai');
error_reporting(E_ALL | E_STRICT);
require_once 'PHPUnit/Framework.php';
require_once 'PHPUnit/Framework/TestSuite.php';
require dirname(__FILE__) . '/../../library/q.php';
Q::changeIni('runtime_cache_dir', dirname(__FILE__) . '/../../tmp');
Q::changeIni('log_writer_dir', dirname(__FILE__) . '/../../tmp');
define('FIXTURE_DIR', dirname(dirname(__FILE__)) . DS . 'fixture');
/**
 * 载入数据库连接信息
 */
$dsn_pool = Helper_YAML::load(FIXTURE_DIR . '/database.yaml');
Q::replaceIni('db_dsn_pool', $dsn_pool);
PHPUnit_Util_Filter::addDirectoryToFilter(dirname(dirname(__FILE__)));
abstract class QTest_UnitTest_Abstract extends PHPUnit_Framework_TestCase
{
    protected function assertEmpty($var, $msg = '')
    {
        $this->assertTrue(empty($var), $msg);
    }
    protected function assertNotEmpty($var, $msg = '')
    {
        $this->assertTrue(!empty($var), $msg);
    }
}
abstract class QTest_UnitTest_TestSuite_Abstract extends PHPUnit_Framework_TestSuite
{
}
Esempio n. 5
0
 /**
  * 获得一个数据库连接对象
  *
  * $dsn_name 参数指定要使用应用程序设置中的哪一个项目作为创建数据库连接的 DSN 信息。
  * 对于同样的 DSN 信息,只会返回一个数据库连接对象。
  *
  * 所有的数据库连接信息都存储在应用程序设置 db_dsn_pool 中。
  * 默认的数据库连接信息存储为 db_dsn_pool/default。
  *
  * @code php
  * // 获得默认数据库连接对应的数据库访问对象
  * $dbo = QDB::getConn();
  *
  * // 获得数据库连接信息 db_dsn_pool/news_db 对应的数据库访问对象
  * $dbo_news = QDB::getConn('news_db');
  * @endcode
  *
  * @param string $dsn_name 要使用的数据库连接
  *
  * @return QDB_Adapter_Abstract 数据库访问对象
  */
 static function getConn($dsn_name = null)
 {
     $default = empty($dsn_name);
     if ($default && Q::isRegistered('dbo_default')) {
         return Q::registry('dbo_default');
     }
     if (empty($dsn_name)) {
         $dsn = Q::ini('db_dsn_pool/default');
     } else {
         $dsn = Q::ini('db_dsn_pool/' . $dsn_name);
     }
     if (!empty($dsn['_use'])) {
         $used_dsn = Q::ini("db_dsn_pool/{$dsn['_use']}");
         $dsn = array_merge($dsn, $used_dsn);
         unset($dsn['_use']);
         if ($dsn_name && !empty($dsn)) {
             Q::replaceIni("db_dsn_pool/{$dsn_name}", $dsn);
         }
     }
     if (empty($dsn)) {
         // LC_MSG: Invalid DSN.
         trigger_error('invalid dsn');
         throw new QException(__('Invalid DSN.'));
     }
     $dbtype = $dsn['driver'];
     $objid = "dbo_{$dbtype}_" . md5(serialize($dsn));
     if (Q::isRegistered($objid)) {
         return Q::registry($objid);
     }
     $class_name = 'QDB_Adapter_' . ucfirst($dbtype);
     $dbo = new $class_name($dsn, $objid);
     Q::register($dbo, $objid);
     if ($default) {
         Q::register($dbo, 'dbo_default');
     }
     return $dbo;
 }
Esempio n. 6
0
 protected function _getDBO()
 {
     $dsn = Q::ini('managed_app_ini/db_dsn_pool/default');
     if (!empty($dsn['_use'])) {
         $used_dsn = Q::ini("managed_app_ini/db_dsn_pool/{$dsn['_use']}");
         $dsn = array_merge($dsn, $used_dsn);
         unset($dsn['_use']);
         if (!empty($dsn)) {
             Q::replaceIni("managed_app_ini/db_dsn_pool/default", $dsn);
         }
     }
     $dbtype = $dsn['driver'];
     $objid = "dbo_{$dbtype}_" . md5(serialize($dsn));
     $class_name = 'QDB_Adapter_' . ucfirst($dbtype);
     return new $class_name($dsn, $objid);
 }