本文整理汇总了PHP中fORM::getDatabaseName方法的典型用法代码示例。如果您正苦于以下问题:PHP fORM::getDatabaseName方法的具体用法?PHP fORM::getDatabaseName怎么用?PHP fORM::getDatabaseName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类fORM
的用法示例。
在下文中一共展示了fORM::getDatabaseName方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testClassToDatabaseMapping
public function testClassToDatabaseMapping()
{
$this->assertEquals('default', fORM::getDatabaseName('User'));
$this->assertEquals('default', fORM::getDatabaseName('PhotoGallery'));
fORM::mapClassToDatabase('User', 'second_db');
$this->assertEquals('second_db', fORM::getDatabaseName('User'));
}
示例2: retrieve
/**
* Return the instance of the fSchema class
*
* @param string $class The class the object will be used with
* @return fSchema The schema instance
*/
public static function retrieve($class = 'fActiveRecord')
{
if (substr($class, 0, 5) == 'name:') {
$database_name = substr($class, 5);
} else {
$database_name = fORM::getDatabaseName($class);
}
if (!isset(self::$schema_objects[$database_name])) {
self::$schema_objects[$database_name] = new fSchema(fORMDatabase::retrieve($class));
}
return self::$schema_objects[$database_name];
}
示例3: retrieve
/**
* Return the instance of the fDatabase class
*
* @param string $class The class to retrieve the database for - if not specified, the default database will be returned
* @param string $role If the database will be used for `'write'`, `'read'` or `'either'` operations
* @return fDatabase The database instance
*/
public static function retrieve($class = 'fActiveRecord', $role = 'either')
{
if (substr($class, 0, 5) == 'name:') {
$database_name = substr($class, 5);
} else {
$database_name = fORM::getDatabaseName($class);
}
if (!isset(self::$database_objects[$database_name])) {
throw new fProgrammerException('The database object named "%1$s" has not been attached via %2$s yet', $database_name, __CLASS__ . '::attach()');
}
if ($role == 'write' || $role == 'read') {
// If the user wants a read database but we are in a transaction on the write database, return
// the write database to allow for comparing data changed since the transaction started
if ($role == 'read' && isset(self::$database_objects[$database_name]['write']) && self::$database_objects[$database_name]['write']->isInsideTransaction()) {
$role = 'write';
}
if (!isset(self::$database_objects[$database_name][$role])) {
throw new fProgrammerException('The database object named "%1$s" for the %s$2 role has not been attached via %3$s yet', $database_name, $role, __CLASS__ . '::attach()');
}
return self::$database_objects[$database_name][$role];
}
if (isset(self::$database_objects[$database_name]['write'])) {
return self::$database_objects[$database_name]['write'];
} elseif (isset(self::$database_objects[$database_name]['read'])) {
return self::$database_objects[$database_name]['read'];
}
}