- Timestamp:
- 06/21/06 14:09:13 (3 years ago)
- Files:
-
- 1 modified
-
Zend/Perms.php (modified) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
Zend/Perms.php
r18 r19 10 10 private static $_gmp = NULL; 11 11 12 private static $_callback; 12 private static $_group_callback; 13 14 private static $_perm_callback; 13 15 /** 14 16 * Stores the permissions array … … 19 21 */ 20 22 private static $_perm_array; 23 24 /** 25 * Stores group permissions in an array 26 * $array['Admin'][] = 1; 27 * $array['Admin'][] = 2; 28 * $array['Admin'][] = 4; 29 * $array['Admin'][] = 8; 30 */ 31 private static $_group_array; 32 21 33 /** 22 34 * Holds a reference to the variable to verify againsts … … 29 41 * would only work AFTER start session has been called 30 42 */ 31 public static function initPerms(&$user_value, $ callback = NULL, $gmpoverride = 1) {43 public static function initPerms(&$user_value, $perm_callback = NULL, $group_callback = NULL, $gmpoverride = 1) { 32 44 self::$_user_value = &$user_value; 33 self::$_callback = $callback; 45 self::$_perm_callback = $perm_callback; 46 self::$_group_callback = $group_callback; 34 47 if(function_exists('gmp_add') AND $gmpoverride) { 35 48 self::$_gmp = 1; … … 41 54 */ 42 55 public static function permCheck($value) { 43 if(!isset(self::$_perm_array) AND self::$_ callback) {44 self::loadCallback(self::$_ callback);56 if(!isset(self::$_perm_array) AND self::$_perm_callback) { 57 self::loadCallback(self::$_perm_callback); 45 58 } 46 59 if(!isset(self::$_perm_array)) { … … 61 74 * Single value, go ahead and check, return true if success 62 75 */ 63 } elseif(isset(self::$_perm_array[$value]) AND (self::bit _and(self::$_perm_array[$value], self::$_user_value))) {76 } elseif(isset(self::$_perm_array[$value]) AND (self::bitAnd(self::$_perm_array[$value], self::$_user_value))) { 64 77 return true; 65 78 } 66 79 return false; 67 80 } 81 82 public static function groupCheck($group) { 83 if(!isset(self::$_group_array) AND self::$_group_callback) { 84 self::loadCallback(self::$_group_callback); 85 } 86 if(!isset(self::$_group_array)) { 87 throw new Zend_Perms_Exception('No group permissions have been loaded'); 88 } 89 if(!isset(self::$_group_array[$group])) { 90 return false; 91 } 92 foreach(self::$_group_array[$group] as $key) { 93 if(!bitAnd($key, self::$_user_value)) { 94 return false; 95 } 96 } 97 } 68 98 69 99 /** … … 86 116 87 117 /** 88 * Loads the verification array from a database118 * Loads the permissions from a callback function 89 119 */ 90 private static function loadCallback($callback ) {120 private static function loadCallback($callback, $group = 0) { 91 121 if(is_callable($callback)) { 92 call_user_func($callback); 122 if($group) { 123 self::$_group_array = call_user_func($callback); 124 } else { 125 self::$_perm_array = call_user_func($callback); 126 } 93 127 } else { 94 throw new Zend_Config_Exception(' Callback function is not available');128 throw new Zend_Config_Exception('Permissions Callback function is not available'); 95 129 } 96 130 }
