search
Homephp教程php手册二进制交叉权限微型php类详解

二进制交叉权限微型php类详解

Jun 13, 2016 am 09:43 AM
phpmainbinaryarticlePermissionskindDetailed explanation

 这篇文章主要介绍了二进制交叉权限微型php类,需要的朋友可以参考下

靓点: 1、多对多交叉场景分配; 2、php新特性-闭包使用、批处理函数array_walk/array_flip使用; 3、位运算&使用案例;   使用场景: 1、常见增删改查(2的N次方值入库); 2、认证、第三方账号绑定、多分类选择;    代码如下: 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
Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.