本文整理汇总了PHP中app\Role::getRoleMaskByID方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::getRoleMaskByID方法的具体用法?PHP Role::getRoleMaskByID怎么用?PHP Role::getRoleMaskByID使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Role
的用法示例。
在下文中一共展示了Role::getRoleMaskByID方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getPermissions
/**
* Return the user's entire permission object,
* build it if nessecary.
*
* @return array
*/
protected function getPermissions()
{
if (!isset($this->permissions)) {
$rememberTags = ["user.{$this->user_id}", "permissions"];
$rememberTimer = 3600;
$rememberKey = "user.{$this->user_id}.permissions";
$rememberClosure = function () {
$permissions = [];
// Fetch our permission mask.
if ($this->isAnonymous()) {
$permissions["anonymous"] = Role::getRoleMaskByName("anonymous");
if (!$this->isAccountable()) {
$permissions["unaccountable"] = Role::getRoleMaskByName("unaccountable");
}
} else {
$userRoles = [];
foreach ($this->roles as $role) {
$userRoles[] = $role->role_id;
}
if (!count($userRoles)) {
$permissions = Role::getRoleMaskByName("anonymous");
} else {
$permissions = Role::getRoleMaskByID($userRoles);
}
}
return $permissions;
};
switch (env('CACHE_DRIVER')) {
case "file":
case "database":
$this->permissions = Cache::remember($rememberKey, $rememberTimer, $rememberClosure);
break;
default:
$this->permissions = Cache::tags($rememberTags)->remember($rememberKey, $rememberTimer, $rememberClosure);
break;
}
}
return $this->permissions;
}
示例2: getPermissions
/**
* Return the user's entire permission object,
* build it if nessecary.
*
* @return array
*/
protected function getPermissions()
{
if (!isset($this->permissions)) {
$this->permissions = Cache::remember("user.{$this->user_id}.permissions", 3600, function () {
$permissions = [];
// Fetch our permission mask.
if ($this->isAnonymous()) {
$permissions["anonymous"] = Role::getRoleMaskByName("anonymous");
if (!$this->isAccountable()) {
$permissions["unaccountable"] = Role::getRoleMaskByName("unaccountable");
}
} else {
$userRoles = [];
foreach ($this->roles as $role) {
$userRoles[] = $role->role_id;
}
if (!count($userRoles)) {
$permissions = Role::getRoleMaskByName("anonymous");
} else {
$permissions = Role::getRoleMaskByID($userRoles);
}
}
return $permissions;
});
}
return $this->permissions;
}