web/lib/Zend/Acl.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    12  * obtain it through the world-wide-web, please send an email
    13  * to license@zend.com so we can send you a copy immediately.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category   Zend
    15  * @category   Zend
    16  * @package    Zend_Acl
    16  * @package    Zend_Acl
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version    $Id: Acl.php 23358 2010-11-18 16:19:31Z ralph $
    19  * @version    $Id: Acl.php 24771 2012-05-07 01:13:06Z adamlundrigan $
    20  */
    20  */
    21 
    21 
    22 
    22 
    23 /**
    23 /**
    24  * @see Zend_Acl_Resource_Interface
    24  * @see Zend_Acl_Resource_Interface
    51 
    51 
    52 
    52 
    53 /**
    53 /**
    54  * @category   Zend
    54  * @category   Zend
    55  * @package    Zend_Acl
    55  * @package    Zend_Acl
    56  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    56  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    57  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    57  * @license    http://framework.zend.com/license/new-bsd     New BSD License
    58  */
    58  */
    59 class Zend_Acl
    59 class Zend_Acl
    60 {
    60 {
    61     /**
    61     /**
   138      * from different parents, the most recently added parent takes precedence over
   138      * from different parents, the most recently added parent takes precedence over
   139      * parents that were previously added. In other words, the first parent added
   139      * parents that were previously added. In other words, the first parent added
   140      * will have the least priority, and the last parent added will have the
   140      * will have the least priority, and the last parent added will have the
   141      * highest priority.
   141      * highest priority.
   142      *
   142      *
   143      * @param  Zend_Acl_Role_Interface              $role
   143      * @param  Zend_Acl_Role_Interface|string       $role
   144      * @param  Zend_Acl_Role_Interface|string|array $parents
   144      * @param  Zend_Acl_Role_Interface|string|array $parents
   145      * @uses   Zend_Acl_Role_Registry::add()
   145      * @uses   Zend_Acl_Role_Registry::add()
   146      * @return Zend_Acl Provides a fluent interface
   146      * @return Zend_Acl Provides a fluent interface
   147      */
   147      */
   148     public function addRole($role, $parents = null)
   148     public function addRole($role, $parents = null)
   653             foreach ($this->_resources as $rTarget) {
   653             foreach ($this->_resources as $rTarget) {
   654                 $allResources[] = $rTarget['instance'];
   654                 $allResources[] = $rTarget['instance'];
   655             }
   655             }
   656             unset($rTarget);
   656             unset($rTarget);
   657         }
   657         }
   658         
   658 
   659         // normalize privileges to array
   659         // normalize privileges to array
   660         if (null === $privileges) {
   660         if (null === $privileges) {
   661             $privileges = array();
   661             $privileges = array();
   662         } else if (!is_array($privileges)) {
   662         } else if (!is_array($privileges)) {
   663             $privileges = array($privileges);
   663             $privileges = array($privileges);
   724                                             'byPrivilegeId' => array()
   724                                             'byPrivilegeId' => array()
   725                                             );
   725                                             );
   726                                     }
   726                                     }
   727                                     continue;
   727                                     continue;
   728                                 }
   728                                 }
   729     
   729 
   730                                 if (isset($rules['allPrivileges']['type']) &&
   730                                 if (isset($rules['allPrivileges']['type']) &&
   731                                     $type === $rules['allPrivileges']['type'])
   731                                     $type === $rules['allPrivileges']['type'])
   732                                 {
   732                                 {
   733                                     unset($rules['allPrivileges']);
   733                                     unset($rules['allPrivileges']);
   734                                 }
   734                                 }
   748                     foreach ($roles as $role) {
   748                     foreach ($roles as $role) {
   749                         /**
   749                         /**
   750                          * since null (all resources) was passed to this setRule() call, we need
   750                          * since null (all resources) was passed to this setRule() call, we need
   751                          * clean up all the rules for the global allResources, as well as the indivually
   751                          * clean up all the rules for the global allResources, as well as the indivually
   752                          * set resources (per privilege as well)
   752                          * set resources (per privilege as well)
   753                          */ 
   753                          */
   754                         foreach (array_merge(array(null), $allResources) as $resource) {
   754                         foreach (array_merge(array(null), $allResources) as $resource) {
   755                             $rules =& $this->_getRules($resource, $role, true);
   755                             $rules =& $this->_getRules($resource, $role, true);
   756                             if (null === $rules) {
   756                             if (null === $rules) {
   757                                 continue;
   757                                 continue;
   758                             }
   758                             }
   767                                             'byPrivilegeId' => array()
   767                                             'byPrivilegeId' => array()
   768                                             );
   768                                             );
   769                                     }
   769                                     }
   770                                     continue;
   770                                     continue;
   771                                 }
   771                                 }
   772     
   772 
   773                                 if (isset($rules['allPrivileges']['type']) && $type === $rules['allPrivileges']['type']) {
   773                                 if (isset($rules['allPrivileges']['type']) && $type === $rules['allPrivileges']['type']) {
   774                                     unset($rules['allPrivileges']);
   774                                     unset($rules['allPrivileges']);
   775                                 }
   775                                 }
   776                             } else {
   776                             } else {
   777                                 foreach ($privileges as $privilege) {
   777                                 foreach ($privileges as $privilege) {
  1216 
  1216 
  1217         return $this->_getRoleRegistry()->getRoles();
  1217         return $this->_getRoleRegistry()->getRoles();
  1218     }
  1218     }
  1219 
  1219 
  1220     /**
  1220     /**
       
  1221      * Returns an array of registered roles.
       
  1222      *
       
  1223      * Note that this method does not return instances of registered roles,
       
  1224      * but only the role identifiers.
       
  1225      *
  1221      * @return array of registered roles
  1226      * @return array of registered roles
  1222      */
  1227      */
  1223     public function getRoles()
  1228     public function getRoles()
  1224     {
  1229     {
  1225         return array_keys($this->_getRoleRegistry()->getRoles());
  1230         return array_keys($this->_getRoleRegistry()->getRoles());
  1230      */
  1235      */
  1231     public function getResources()
  1236     public function getResources()
  1232     {
  1237     {
  1233         return array_keys($this->_resources);
  1238         return array_keys($this->_resources);
  1234     }
  1239     }
  1235     
  1240 
  1236 }
  1241 }
  1237     
  1242