php权限二进制,PHP_二进制交叉权限微型php类分享,靓点:1、多对多交叉场景分配 - phpStudy...

class s_allow{

//声明使用场景,任务清单

public $scene,$case_list=array();

//声明指定用户角色、允许值、允许清单

public $allow_value=0,$allow_list=array();

//初始化场景、角色

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);

}

}

//取得全部任务清单

function case_list($mode=false){

$case_list=config($this->scene,'allow');

return $mode ? $case_list : array_keys($case_list);

}

//取得用户任务清单

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);

}

//计算允许值

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));

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值