Nette\Security\Permission::addRole PHP Метод

addRole() публичный Метод

Adds a Role to the list. The most recently added parent takes precedence over parents that were previously added.
public addRole ( $role, $parents = NULL ) : self
Результат self
    public function addRole($role, $parents = NULL)
    {
        $this->checkRole($role, FALSE);
        if (isset($this->roles[$role])) {
            throw new Nette\InvalidStateException("Role '{$role}' already exists in the list.");
        }
        $roleParents = [];
        if ($parents !== NULL) {
            if (!is_array($parents)) {
                $parents = [$parents];
            }
            foreach ($parents as $parent) {
                $this->checkRole($parent);
                $roleParents[$parent] = TRUE;
                $this->roles[$parent]['children'][$role] = TRUE;
            }
        }
        $this->roles[$role] = ['parents' => $roleParents, 'children' => []];
        return $this;
    }

Usage Example

Пример #1
0
 /**
  * Definice rolí.
  */
 private function defineRoles()
 {
     $groups = $this->permissionRepository->selectAllGroups();
     $this->acl->addRole("Guest");
     foreach ($groups as $group) {
         $this->acl->addRole($group->getName(), $group->getExtendsGroup()->getName());
     }
 }
All Usage Examples Of Nette\Security\Permission::addRole