本文整理匯總了PHP中Q::registry方法的典型用法代碼示例。如果您正苦於以下問題:PHP Q::registry方法的具體用法?PHP Q::registry怎麽用?PHP Q::registry使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Q
的用法示例。
在下文中一共展示了Q::registry方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getConn
/**
* 獲得一個數據庫連接對象
*
* $dsn_name 參數指定要使用應用程序設置中的哪一個項目作為創建數據庫連接的 DSN 信息。
* 對於同樣的 DSN 信息,隻會返回一個數據庫連接對象。
*
* @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::getIni('db_dsn_pool/default');
} else {
$dsn = Q::getIni('db_dsn_pool/' . $dsn_name);
}
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;
}
示例2: testRegister
/**
* 測試對象注冊
*/
function testRegister()
{
$obj1 = new Class2();
Q::register($obj1);
Q::register($obj1, 'object-1-1');
$this->assertTrue(Q::isRegistered('class2'));
$this->assertTrue(Q::isRegistered('Class2'));
$this->assertFalse(Q::isRegistered('class22'));
$obj = Q::registry('class2');
$this->assertSame($obj1, $obj);
$obj = Q::registry('object-1-1');
$this->assertSame($obj1, $obj);
}
示例3: _tableByClass
/**
* 根據類名稱獲得表數據入口對象
*
* @param string $table_class
* @param array $table_config
*
* @return QDB_Table
*/
protected function _tableByClass($table_class, array $table_config = array())
{
$obj_id = 'activerecord_table_' . strtolower($table_class);
if (Q::isRegistered($obj_id)) {
return Q::registry($obj_id);
} else {
$table = new $table_class($table_config);
Q::register($table, $obj_id);
return $table;
}
}
示例4: _renderBlock
/**
* 渲染指定的視圖文件
*
* 渲染時,視圖要使用的數據保存在控件的 $view 屬性中。
*
* @param string $viewname
* @param boolean $return
*
* @return string
*/
protected function _renderBlock($viewname, $return = false)
{
if (!is_object($this->_view_adapter)) {
$adapter_class = is_null($this->_view_adapter_class) ? $this->context->getIni('view_adapter') : $this->_view_adapter_class;
$adapter_obj_id = "webcontrols_{$adapter_class}";
if (Q::isRegistered($adapter_obj_id)) {
/**
* @var QView_Adapter_Abstract
*/
$adapter = Q::registry($adapter_obj_id);
} else {
/**
* @var QView_Adapter_Abstract
*/
$adapter = new $adapter_class($this->context);
Q::register($adapter, $adapter_obj_id);
}
} else {
$adapter = $this->_view_adapter;
}
$adapter->clear();
$adapter->assign($this->view);
$adapter->assign('_ctx', $this->context);
$filename = QView::getControlViewFilename($this->context, $adapter, $viewname, $this->_controls_view_dir);
if ($return) {
return $adapter->fetch($filename);
} else {
return $adapter->display($filename);
}
}
示例5: render
/**
* 渲染表單
*
* @param QContext $context
* @param boolean $return
*
* @return string
*/
function render(QContext $context, $return = false)
{
$this->_event(self::BEFORE_RENDER_FORM, $this);
if (!is_object($this->_view_adapter)) {
$adapter_class = is_null($this->_view_adapter_class) ? $context->getIni('view_adapter') : $this->_view_adapter_class;
$adapter_obj_id = "form_{$adapter_class}";
if (Q::isRegistered($adapter_obj_id)) {
$adapter = Q::registry($adapter_obj_id);
} else {
$adapter = new $adapter_class($context);
Q::register($adapter, $adapter_obj_id);
}
} else {
$adapter = $this->_view_adapter;
}
/* @var $adapter QView_Adapter_Abstract */
$viewname = !empty($this->_viewname) ? $this->_viewname : 'form';
$filename = QView::getViewLayoutsFilename($adapter->context, $adapter, $viewname);
$adapter->clear();
$adapter->assign('form', $this);
$adapter->assign('_ctx', $context);
$output = $adapter->fetch($filename);
$this->_event(self::AFTER_RENDER_FORM, $this);
if (!$return) {
echo $output;
$output = null;
}
return $output;
}