Authority. class. php modify the permission to be verified $ name if the permission list does not exist, this permission is granted by default-PHP source code

Source: Internet
Author: User
Authority. class. php modify the permission to be verified $ name if the permission list does not exist, this permission is granted to php code by default.

// Get the permission $ name can be a string or an array or separated by commas. uid is the authenticated user ID, $ or is in the or relation, true is, and name is an array, if one of the conditions in the array is passed, it is passed. if it is false, all conditions must pass. // Last modification function: permission to be verified $ name if the permission list does not exist, this permission is granted by default to public function getAuth ($ name, $ uid, $ relation = 'or ') {if (! $ This-> _ config ['auth _ on']) return true; $ authList = $ this-> getAuthList ($ uid); if (is_string ($ name )) {if (strpos ($ name ,',')! = False) {$ name = explode (',', $ name);} else {$ name = array ($ name );}} // modify the part to start foreach ($ name as $ key => $ val) {if (! $ This-> isExistsRule ($ val) {unset ($ name [$ key]) ;}} if (count ($ name) == 0) {return true ;} // end of modifying part $ list = array (); // name foreach ($ authList as $ val) with permission {if (in_array ($ val, $ name )) $ list [] = $ val;} if ($ relation = 'or' and! Empty ($ list) {return true;} $ diff = array_diff ($ name, $ list); if ($ relation = 'and' and empty ($ diff )) {return true;} return false;}/*** @ desc determines whether the database has the permission * @ param string $ name RuleName */public function isExistsRule ($ name) {static $ rule = array (); if (! Empty ($ rule [$ name]) {return $ rule [$ name];} $ rule [$ name] = M () -> table ($ this-> _ config ['auth _ rule'])-> where (array ('name' => $ name)-> count (); return $ rule [$ name];}

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.