Binary cross-permission micro php class-PHP source code

Source: Internet
Author: User
Binary cross-permission micro php:
1. Multi-to-multi-cross scenario allocation;
2. new features of php-use of closures and use of the batch processing function array_walk/array_flip;
3. bitwise operations & use cases;

Use cases:
1. common addition, deletion, modification, and query (the n value of 2 is stored in the database );
2. authentication, third-party account binding, and multi-category selection;

 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) ;}// obtain the function case_list of all tasks ($ mode = false) {$ case_list = config ($ this-> scene, 'allow'); return $ mode? $ Case_list: array_keys ($ case_list);} // obtain the 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);} // calculate 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 whether function is_allow ($ case) {$ case_list = array_flip ($ this-> case_list); return (bool) ($ this-> allow_value & pow (2, $ case_list [$ case]-1 ));}}


[access]1=add2=del3=read4=list5=mod6=detail7=pub8=collect9=like10=send[cert]1=email2=tel3=qq4=identity_card5=real_name6=business_license[bind]1=qq2=weibo3=taobao4=alipay5=renren6=weichat7=baidu

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.