本文整理匯總了PHP中context::systemcontext方法的典型用法代碼示例。如果您正苦於以下問題:PHP context::systemcontext方法的具體用法?PHP context::systemcontext怎麽用?PHP context::systemcontext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類context
的用法示例。
在下文中一共展示了context::systemcontext方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: instance
/**
* Returns system context instance.
*
* @static
* @param int $instanceid
* @param int $strictness
* @param bool $cache
* @return context_system context instance
*/
public static function instance($instanceid = 0, $strictness = MUST_EXIST, $cache = true)
{
global $DB;
if ($instanceid != 0) {
debugging('context_system::instance(): invalid $id parameter detected, should be 0');
}
if (defined('SYSCONTEXTID') and $cache) {
// dangerous: define this in config.php to eliminate 1 query/page
if (!isset(context::$systemcontext)) {
$record = new stdClass();
$record->id = SYSCONTEXTID;
$record->contextlevel = CONTEXT_SYSTEM;
$record->instanceid = 0;
$record->path = '/' . SYSCONTEXTID;
$record->depth = 1;
context::$systemcontext = new context_system($record);
}
return context::$systemcontext;
}
try {
// we ignore the strictness completely because system context must except except during install
$record = $DB->get_record('context', array('contextlevel' => CONTEXT_SYSTEM), '*', MUST_EXIST);
} catch (dml_exception $e) {
//table or record does not exist
if (!during_initial_install()) {
// do not mess with system context after install, it simply must exist
throw $e;
}
$record = null;
}
if (!$record) {
$record = new stdClass();
$record->contextlevel = CONTEXT_SYSTEM;
$record->instanceid = 0;
$record->depth = 1;
$record->path = null;
//not known before insert
try {
if ($DB->count_records('context')) {
// contexts already exist, this is very weird, system must be first!!!
return null;
}
if (defined('SYSCONTEXTID')) {
// this would happen only in unittest on sites that went through weird 1.7 upgrade
$record->id = SYSCONTEXTID;
$DB->import_record('context', $record);
$DB->get_manager()->reset_sequence('context');
} else {
$record->id = $DB->insert_record('context', $record);
}
} catch (dml_exception $e) {
// can not create context - table does not exist yet, sorry
return null;
}
}
if ($record->instanceid != 0) {
// this is very weird, somebody must be messing with context table
debugging('Invalid system context detected');
}
if ($record->depth != 1 or $record->path != '/' . $record->id) {
// fix path if necessary, initial install or path reset
$record->depth = 1;
$record->path = '/' . $record->id;
$DB->update_record('context', $record);
}
if (!defined('SYSCONTEXTID')) {
define('SYSCONTEXTID', $record->id);
}
context::$systemcontext = new context_system($record);
return context::$systemcontext;
}