Changeset 19 for Zend

Show
Ignore:
Timestamp:
06/21/06 14:09:13 (3 years ago)
Author:
richard
Message:

Group functionality added

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • Zend/Perms.php

    r18 r19  
    1010  private static $_gmp = NULL; 
    1111 
    12         private static $_callback; 
     12  private static $_group_callback; 
     13 
     14        private static $_perm_callback; 
    1315        /** 
    1416         * Stores the permissions array 
     
    1921         */ 
    2022        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 
    2133        /** 
    2234         * Holds a reference to the variable to verify againsts 
     
    2941         * would only work AFTER start session has been called 
    3042         */ 
    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) { 
    3244                self::$_user_value = &$user_value; 
    33     self::$_callback = $callback; 
     45    self::$_perm_callback = $perm_callback; 
     46    self::$_group_callback = $group_callback; 
    3447    if(function_exists('gmp_add') AND $gmpoverride) { 
    3548      self::$_gmp = 1; 
     
    4154         */ 
    4255        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); 
    4558                } 
    4659                if(!isset(self::$_perm_array)) { 
     
    6174                 * Single value, go ahead and check, return true if success 
    6275                 */ 
    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))) { 
    6477                        return true; 
    6578                } 
    6679                return false; 
    6780        } 
     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  } 
    6898 
    6999  /** 
     
    86116 
    87117        /** 
    88          * Loads the verification array from a database 
     118         * Loads the permissions from a callback function 
    89119         */ 
    90         private static function loadCallback($callback) { 
     120        private static function loadCallback($callback, $group = 0) { 
    91121    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      } 
    93127    } else { 
    94       throw new Zend_Config_Exception('Callback function is not available'); 
     128      throw new Zend_Config_Exception('Permissions Callback function is not available'); 
    95129    } 
    96130        }