Binary Cross permission miniature PHP class detailed

Source: Internet
Author: User
Tags php class pow

  This article mainly introduces the binary cross permission micro-PHP class, the need for friends can refer to the following

Beautiful point: 1, multiple cross scene allocation; 2, PHP new features-closure use, batch function array_walk/array_flip use; 3, bit operation & use case   Use scene: 1, common additions and deletions to check (2 of the N secondary value of storage); 2, certification, Third party account binding, multiple classification selection;     code is as follows: <?php   class s_allow{ //Declaration usage scenario, Task List public $scene, $case _list=array (); nbsp Declares the specified user role, allowable value, allow listing public $allow _value=0, $allow _list=array ();    //initialization scenario, role 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); }    //Get all Task List function case_list ($mode =false) {$case _list=config ($this->scene, ' allow '); return $mode? $case _list:array_keys ($case _list);    //Get User Task 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); }     Computes the Allowed value 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);    //Determine if function Is_allow ($case) {$case _list=array_flip ($this->case_list) is allowed; return (BOOL) ($this- >allow_value & Pow (2, $case _list[$case]-1)); The code is as follows: [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 Chat 7=baidu
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.