Example #1
0
 /**
  * @param RoleInterface|Role $role
  * @param null $parents
  * @return Registry|\Zend\Permissions\Acl\Role\Registry
  */
 public function add(RoleInterface $role, $parents = null)
 {
     if (!$role instanceof Role) {
         return parent::add($role, $parents);
     }
     $roleId = $role->getRoleId();
     $roleParents = array();
     /** @var $child Role */
     foreach ($role->getParents() as $parent) {
         $roleParents[$parent->getName()] = $parent;
     }
     $children = array();
     /** @var $child Role */
     foreach ($role->getChildren() as $child) {
         $children[$child->getName()] = $child;
     }
     $this->roles[$roleId] = array('instance' => $role, 'parents' => $roleParents, 'children' => $children);
     return $this;
 }
Example #2
0
 /**
  * Ensures that two Roles having the same ID cannot be registered
  *
  * @return void
  */
 public function testRoleRegistryDuplicateId()
 {
     $roleGuest1 = new Role\GenericRole('guest');
     $roleGuest2 = new Role\GenericRole('guest');
     $roleRegistry = new Role\Registry();
     $this->setExpectedException('Zend\\Permissions\\Acl\\Exception\\InvalidArgumentException', 'already exists');
     $roleRegistry->add($roleGuest1)->add($roleGuest2);
 }