本文整理汇总了PHP中app\models\Group::getMergedPermissions方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::getMergedPermissions方法的具体用法?PHP Group::getMergedPermissions怎么用?PHP Group::getMergedPermissions使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\models\Group
的用法示例。
在下文中一共展示了Group::getMergedPermissions方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: hasPermission
public static function hasPermission($permissions, $all = true)
{
$return = true;
$user = Auth::user();
$mergedPermissions = Group::getMergedPermissions($user);
if (isset($mergedPermissions['superuser']) && $mergedPermissions['superuser'] == 1) {
return true;
}
if (!is_array($permissions)) {
$permissions = (array) $permissions;
}
foreach ($permissions as $permission) {
// We will set a flag now for whether this permission was
// matched at all.
$matched = true;
// Now, let's check if the permission ends in a wildcard "*" symbol.
// If it does, we'll check through all the merged permissions to see
// if a permission exists which matches the wildcard.
if (strlen($permission) > 1 && ends_with($permission, '*')) {
$matched = static::format_perm1($mergedPermissions, $permission);
break;
} elseif (strlen($permission) > 1 && starts_with($permission, '*')) {
$matched = static::format_perm($mergedPermissions, $permission);
break;
} else {
$matched = static::format_permission($mergedPermissions, $permission);
break;
}
// Now, we will check if we have to match all
// permissions or any permission and return
// accordingly.
if ($all === true && $matched === false) {
$return = false;
} elseif ($all === false && $matched === true) {
$return = true;
}
}
if ($all === false) {
$return = false;
}
return $return;
}