public function addRoleByName(string $roleName)
    {
        if (!$this->user) {
            throw new UserRequiredException();
        }

        $this->compileUserRoles();

        if ($this->hasRoleWithName($roleName)) {
            return;
        }

        $role = $this->roleProvider->getRoleWithName($roleName);

        if (!$role) {
            throw new InvalidRoleException($roleName);
        }

        $this->user->addRole($role);
        $this->userRoles[] = $roleName;
        $this->userProvider->update($this->user);
    }
public function addRoleByName(string $roleName)
    {
        if (!$this->user) {
            throw new UserRequiredException();
        }

        $this->compileUserRoles();

        if ($this->hasRoleWithName($roleName)) {
            return;
        }

        $role = $this->roleProvider->getRoleWithName($roleName);

        if (!$role) {
            throw new InvalidRoleException($roleName);
        }

        $this->user->addRole($role);
        $this->userRoles[] = $roleName;
        $this->userProvider->update($this->user);
    }
public function addRoleByName ( string $ roleName ) { if ( ! $ this -> user ) { throw new UserRequiredException ( ) ; } $ this -> compileUserRoles ( ) ; if ( $ this -> hasRoleWithName ( $ roleName ) ) { return ; } $ role = $ this -> roleProvider -> getRoleWithName ( $ roleName ) ; if ( ! $ role ) { throw new InvalidRoleException ( $ roleName ) ; } $ this -> user -> addRole ( $ role ) ; $ this -> userRoles [ ] = $ roleName ; $ this -> userProvider -> update ( $ this -> user ) ; }
Add a role for the current User

@param $roleName

@throws InvalidRoleException
@throws UserRequiredException
@internal param $roleId
Add a role for the current User