靓点:
1、多对多交叉场景分配;
2、php新特性-闭包使用、批处理函数array_walk/array_flip使用;
3、位运算&使用案例;
使用场景:
1、常见增删改查(2的N次方值入库);
2、认证、第三方账号绑定、多分类选择;
复制代码 代码如下:
<?php
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));
}
}
复制代码 代码如下:
[access]
1=add
2=del
3=read
4=list
5=mod
6=detail
7=pub
8=collect
9=like
10=send
[cert]
1=email
2=tel
3=qq
4=identity_card
5=real_name
6=business_license
[bind]
1=qq
2=weibo
3=taobao
4=alipay
5=renren
6=weichat
7=baidu
二进制,交叉权限,微型php
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- 华少翌.2005-华少翌【中唱艺能】【WAV+CUE】
- 群星《十二女声Ⅱ》[WAV/CUE/分轨][527MB]
- 大自然音乐系列《漫步在山裡》[WAV/CUE/分轨][502.8MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]
- 史依弘《史依弘交响乐京剧演唱专辑HQ》头版限量编号[WAV+CUE]
- 曼丽2020《女人三十风继续吹》HQCD[WAV+CUE]
- 曼丽2021《女人三十2雾之恋》HQCD[WAV+CUE]
- 隔壁老樊.2019-我曾【好听音乐】【FLAC分轨】
- 高林生.1993-牵挂你的人是我【白天鹅】【WAV+CUE】
- 洪卓立.2012-找个懂我的女孩(国专)【英皇娱乐】【WAV+CUE】
- 曼丽2022《女人三十3晚秋》HQCD[WAV+CUE]
- 曼丽2018《女人三十4冬天》HQCD[WAV+CUE]
- 柏菲-《好歌30年壹》限量开盘母带ORMCD[低速原抓WAV+CUE]
- 大自然音乐系列《水舞》[WAV/CUE/分轨][424.3MB]
- 大自然音乐系列《星光夜语》[WAV/CUE/分轨][453.3MB]