php权限二进制,PHP_二进制交叉权限微型php类分享,靓点:1、多对多交叉场景分配 - phpStudy...
class s_allow{
//聲明使用場(chǎng)景,任務(wù)清單
public $scene,$case_list=array();
//聲明指定用戶角色、允許值、允許清單
public $allow_value=0,$allow_list=array();
//初始化場(chǎng)景、角色
function __construct($scene,$allow_value=0){
$this->scene=$scene;
$this->case_list=$this->case_list(true);
if ($allow_value) {
$this->allow_value=$allow_value;
$this->allow_list=$this->allow_list($allow_value,true);
}
}
//取得全部任務(wù)清單
function case_list($mode=false){
$case_list=config($this->scene,'allow');
return $mode ? $case_list : array_keys($case_list);
}
//取得用戶任務(wù)清單
function allow_list($allow_value=0,$mode=false){
$buffer=array();
foreach ($this->case_list as $key=>$value) {
if ($allow_value & pow(2,$key-1)) {
$buffer[$key]=$value;
}
}
return $mode ? $buffer : array_keys($buffer);
}
//計(jì)算允許值
function allow_value($allow_list=null){
if ($allow_list==null) $allow_list=$this->allow_list;
array_walk($allow_list, function($value,$key) use(&$allow_list){
$allow_list[$key]=pow(2,$value-1);
});
return array_sum($allow_list);
}
//判斷是否允許
function is_allow($case){
$case_list=array_flip($this->case_list);
return (bool)($this->allow_value & pow(2,$case_list[$case]-1));
}
}
總結(jié)
以上是生活随笔為你收集整理的php权限二进制,PHP_二进制交叉权限微型php类分享,靓点:1、多对多交叉场景分配 - phpStudy...的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java 输入框输入1到9_java程序
- 下一篇: php 树形结构实例,如果用php写树形