@param \Illuminate\Database\Eloquent\Collection|\ViKon\Auth\Model\Role[] $roles

@return void
769082
protected function addRoles(Collection $roles)
    {
        foreach ($roles as $role) {
            $this->roles[] = $role->token;
            $this->addPermissions($role->permissions);
        }
    }
301675
public function whereHasRoleIn(array $roles)
    {
        $managerRoles = array();
        $otherRoles = array();

        foreach ($roles as $role) {
            $roleName = $role instanceof RoleInterface ? $role->getRole() : $role;

            if (preg_match('/^ROLE_WS_MANAGER_/', $roleName)) {
                $managerRoles[] = $roleName;
            } else {
                $otherRoles[] = $roleName;
            }
        }

        $eol = PHP_EOL;

        if (count($otherRoles) > 0 && count($managerRoles) === 0) {
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}";
            $clause .= "rightRole.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol})";
            $this->addWhereClause($clause);
        } elseif (count($otherRoles) === 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $clause = "{$eol}({$eol}";
            $clause .= "role.name IN (:roles){$eol}";
            $this->parameters[":roles"] = $managerRoles;
            $this->addWhereClause($clause . ')');
        } elseif (count($otherRoles) > 0 && count($managerRoles) > 0) {
            $this->leftJoinRoles = true;
            $this->leftJoinRights = true;
            $clause = "{$eol}({$eol}({$eol}";
            $clause .= "rightRole.name IN (:otherroles){$eol}";
            $this->parameters[":otherroles"] = $otherRoles;
            $clause .= "AND{$eol}BIT_AND(rights.mask, 1) = 1{$eol}){$eol}";
            $clause .= "OR{$eol}";
            $clause .= "role.name IN (:managerroles){$eol}";
            $this->parameters[":managerroles"] = $managerRoles;
            $this->addWhereClause($clause . ")");
        }

        return $this;
    }
762548
protected function _setRoles()
    {
        $this->loadModel('Block.Blocks');
        $roles = $this->Blocks->Roles->find('list');
        $this->set('roles', $roles);
    }
1009491
protected function syncRoles(array $roles)
    {
        /** @var \Illuminate\Database\Eloquent\Collection $permissions */
        $permissions = Permission::all();

        foreach ($roles as $roleSlug => $permissionSlug) {
            /** @var  \Arcanesoft\Auth\Models\Role  $role */
            if ($role = Role::query()->where('slug', $roleSlug)->first()) {
                $filtered = $permissions->filter(function (Permission $permission) use ($permissionSlug) {
                    return Str::startsWith($permission->slug, $permissionSlug);
                });

                $role->permissions()->sync(
                    $filtered->pluck('id')->toArray()
                );
            }
        }
    }
147317
public function addRole(Role $role)
    {
        if (!in_array($role, $this->roles)) {
            $this->roles[] = $role;
            return true;
        }
        return false;
    }
1235547
protected function _addRoles($roles)
    {
        foreach ($roles as $name => $parent) {
            if (!$this->hasRole($name)) {
                if (empty($parent)) {
                    $parent = array();
                } else {
                    $parent = explode(',', $parent);
                }

                $this->addRole(new Role($name), $parent);
            }
        }

        return $this;
    }
788065
private function describeRoles(array $roles)
    {
        $withInitials = array_map(function ($role) {
            return sprintf('%s (%s)', $role, substr($role, 0, 1));
        }, $roles);
        $last = array_pop($withInitials);

        return implode(' or ', [implode(', ', $withInitials), $last]);
    }
654806
protected function _addRoles(array $roles) {
        foreach ($roles as $roleName => $properties) {
            // If the properties aren't set as an array, then we will consider
            // the value as the role ID.
            if (!is_array($properties)) {
                $properties = array('id' => $properties);
            }

            $id = $properties['id'];

            if (is_null($id) || empty($id)) {
                throw new Zend_Application_Resource_Exception(
                    sprintf(
                        $this->_missingPropertyMessage, 'ID', 'role', $roleName
                    )
                );
            }
            $this->_addRoleById($roles, $id);
        }
    }
748480
public static function roleGrant($role) {
		// add roles
		if (!empty($role)) {
			// initialize roles array
			if (!isset($_SESSION['numbers']['user']['roles'])) {
				$_SESSION['numbers']['user']['roles'] = [];
			}
			if (!is_array($role)) $role = [$role];
			$_SESSION['numbers']['user']['roles'] = array_unique(array_merge($_SESSION['numbers']['user']['roles'], $role));
		}
	}
1196151
public function syncRoles($roles)
    {
        $sync = [];
        $this->mapArray($roles, function ($role) use (&$sync) {

            $sync[] = $this->parseRoleId($role);

            return $sync;
        });

        return $this->roles()->sync($sync);
    }
1013271
public function updated(Role $role)
    {
        $oldRole = new Role($role->getOriginal());
        $oldRoleName = $oldRole->snake_case_name;
        $newRoleName = $role->snake_case_name;
        if ($newRoleName != $oldRoleName) {
            $this->updateLanguageTerm($oldRoleName, $newRoleName);
        }
    }
1211799
public function eachRole(array $roles, callable $callback)
    {
        $roles = array_flatten($roles);

        foreach ($roles as $role) {
            if ($role = $this->prepareRole($role)) {
                $callback($role);    
            }
        }
    }
150970
public function setRoles(array $roles) {
		
		$this->roles = [];
		
		foreach($roles as $role) {

			if(!$role instanceof Role) {
				throw new \InvalidArgumentException('Role is not a role instance.');
			}
			if(array_key_exists($role->getRoleName(), $this->roles)) {
				throw new \InvalidArgumentException(sprintf("Role '%s' defined twice.", $role->getRoleName()));
			}

			$this->roles[$role->getRoleName()] = $role;

		}

		return $this;
	}
357217
public function hasRoles($roles): bool
    {
        $userRoles = $this->getRoles()->all();

        // We should ensure that all given roles match the current user,
        // consider it as a AND condition instead of OR.
        foreach ((array) $roles as $role) {
            if (! \in_array($role, $userRoles)) {
                return false;
            }
        }

        return true;
    }
793656
public function addRole(string $role, ?array $parents = null): void
    {
        $this->roles[] = $role;
        
        if(null !== $parents) {
            $map = [];
            foreach ($parents as $parent) {
                $map[] = $parent;
                $map = \array_merge($map, $this->getRoles($parent));
            }
            unset($map[0]);
            
            $this->map[$role] = \array_values(\array_unique($map));
        }
    }
298085
public function setRoles($roles) {
        if ($this->configured) throw new IllegalStateException('Configuration is frozen');
        $name = $this->name ? ' name="'.$this->name.'"':'';
        $path = $this->path ? ' path="'.$this->path.'"':'';

        //static $pattern = '/^!?[A-Za-z_][A-Za-z0-9_]*(,!?[A-Za-z_][A-Za-z0-9_]*)*$/';
        static $pattern = '/^!?[A-Za-z_][A-Za-z0-9_]*$/';
        if (!strlen($roles) || !preg_match($pattern, $roles)) throw new StrutsConfigException('<mapping'.$name.$path.' roles="'.$roles.'": Invalid roles expression.');

        // check for invalid id combinations, e.g. "Member,!Member"
        $tokens = explode(',', $roles);
        $keys = \array_flip($tokens);

        foreach ($tokens as $role) {
            if (isset($keys['!'.$role])) throw new StrutsConfigException('<mapping'.$name.$path.' roles="'.$roles.'": Invalid roles expression.');
        }

        // remove duplicates
        $this->roles = join(',', \array_flip($keys));
        return $this;
    }
757789
public function detachRole(...$roles)
    {
        $this->eachRole($roles, function($role) {
            if ($this->hasRole($role)) {
                $this->roles()->detach($role->id);
            }
        });

        return $this;
    }