Neos\Flow\Security\Account::addRole PHP Méthode

addRole() public méthode

Adds a role to this account
public addRole ( Role $role ) : void
$role Neos\Flow\Security\Policy\Role
Résultat void
    public function addRole(Role $role)
    {
        if ($role->isAbstract()) {
            throw new \InvalidArgumentException(sprintf('Abstract roles can\'t be assigned to accounts directly, but the role "%s" is marked abstract', $role->getIdentifier()), 1399900657);
        }
        $this->initializeRoles();
        if (!$this->hasRole($role)) {
            $roleIdentifier = $role->getIdentifier();
            $this->roleIdentifiers[] = $roleIdentifier;
            $this->roles[$roleIdentifier] = $role;
        }
    }

Usage Example

 /**
  * @test
  */
 public function addRoleSkipsRoleIfAssigned()
 {
     $this->account->setRoles([$this->administratorRole]);
     $this->account->addRole($this->administratorRole);
     $this->assertCount(1, $this->account->getRoles());
 }
All Usage Examples Of Neos\Flow\Security\Account::addRole