本文整理汇总了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;
}