本文整理匯總了PHP中JAccess::isRoot方法的典型用法代碼示例。如果您正苦於以下問題:PHP JAccess::isRoot方法的具體用法?PHP JAccess::isRoot怎麽用?PHP JAccess::isRoot使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類JAccess
的用法示例。
在下文中一共展示了JAccess::isRoot方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: check
/**
* Method to check if a user is authorised to perform an action, optionally on an asset.
*
* @param integer Id of the user for which to check authorisation.
* @param string The name of the action to authorise.
* @param mixed Integer asset id or the name of the asset as a string. Defaults to the global asset node.
* @return boolean True if authorised.
* @since 1.6
*/
public static function check($userId, $action, $asset = null)
{
if (self::$isRoot) {
return true;
} else {
// Sanitize inputs.
$userId = (int) $userId;
$action = strtolower(preg_replace('#[\\s\\-]+#', '.', trim($action)));
$asset = strtolower(preg_replace('#[\\s\\-]+#', '.', trim($asset)));
// Default to the root asset node.
if (empty($asset)) {
$asset = 1;
}
// Get the rules for the asset recursively to root if not already retrieved.
if (empty(self::$assetRules[$asset])) {
self::$assetRules[$asset] = self::getAssetRules($asset, true);
}
// Get all groups against which the user is mapped.
$identities = self::getGroupsByUser($userId);
array_unshift($identities, $userId * -1);
// Make sure we only check for core.admin once during the run.
if (self::$isRoot === null) {
if (self::getAssetRules(1)->allow('core.admin', $identities)) {
self::$isRoot = true;
return true;
} else {
self::$isRoot = false;
}
}
return self::$assetRules[$asset]->allow($action, $identities);
}
}