Add multiple roles to data.

@param object $data
@param array  $roles

@return BoundedRoleInterface|object
186196
final protected function addRoles(object $data, array $roles): BoundedRoleInterface
    {
        foreach ($roles as $role) {
            $data = $this->addRole($data, $role);
        }

        return $data;
    }
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));
        }
    }
1196151
public function syncRoles($roles)
    {
        $sync = [];
        $this->mapArray($roles, function ($role) use (&$sync) {

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

            return $sync;
        });

        return $this->roles()->sync($sync);
    }
168049
public function whereRoleIn(array $roles)
    {
        if (0 < $count = count($roles)) {
            $this->leftJoinRights = true;
            $eol = PHP_EOL;
            $clause = "{$eol}({$eol}";

            foreach ($roles as $i => $role) {
                $role = $roles[$i] instanceof RoleInterface ? $roles[$i]->getRole() : $roles[$i];
                $clause .= $i > 0 ? '    OR ' : '    ';
                $clause .= "rightRole.name = :role_{$i}{$eol}";
                $this->parameters[":role_{$i}"] = $role;
            }

            $this->addWhereClause($clause . ')');
        }

        return $this;
    }
1363000
public function updateRole(
        RoleUpdateData $data,
        ?string $name = null
    ): FormInterface {
        $name = $name ?: sprintf('update-role-%d', $data->getRole()->id);

        return $this->formFactory->createNamed($name, RoleUpdateType::class, $data);
    }
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;
	}
1038821
public function setRoles($roles)
    {
        $widget = $this->widget;
        $newRoles = [];
        foreach ($this->availableRoles as $role) {
            $newRoles[$role] = in_array($role, $roles);
        }
        $widget->setOption('roles', $newRoles);
    }
1292753
public function add($role, $inherits = [])
    {
        if (is_scalar($role)) {
            $role = new Role($role);
        } elseif (!$role instanceof Role) {
            throw new \InvalidArgumentException('$role is expected to be of type string or Gobline\Acl\Role');
        }

        $roleName = $role->getName();

        if ($this->has($roleName)) {
            throw new \InvalidArgumentException('Role "'.$roleName.'" already exists');
        }

        if (!is_array($inherits)) {
            $inherits = [$inherits];
        }
        foreach ($inherits as $parent) {
            if (is_scalar($parent)) {
                $parent = $this->get($parent);
            } elseif (!$parent instanceof Role) {
                throw new \InvalidArgumentException('$inherits elements are expected to be of type string or Gobline\Acl\Role');
            }
            $role->addParent($parent);
        }

        $this->roles[$roleName] = $role;

        return $this;
    }
110786
protected function addRoles($roles)
    {
        if (!is_array($roles) && !($roles instanceof \Traversable)) {
            $roles = array($roles);
        }

        /* @var $role Role */
        foreach ($roles as $role) {
            if ($this->acl->hasRole($role)) {
                continue;
            }

            if ($role->getParent() !== null) {
                $this->addRoles(array($role->getParent()));
                $this->acl->addRole($role, $role->getParent());
            } elseif (!$this->acl->hasRole($role)) {
                $this->acl->addRole($role);
            }
        }
    }
39922
public function addDefaultRoles(DefaultRole ...$roles)
    {
        foreach ($roles as $role) {
            $this->getDefaultRoles()->add($role);
        }

        return $this;
    }
74311
public function detachRoles($roles)
    {
        if ($roles instanceof Role) {
            $roles = [$roles->getKey()];
        }

        $this->roles()->detach($roles);

        unset($this->relations['roles']);

        return $this;
    }
769082
protected function addRoles(Collection $roles)
    {
        foreach ($roles as $role) {
            $this->roles[] = $role->token;
            $this->addPermissions($role->permissions);
        }
    }
39604
public function addRole($id, $role)
    {
        if (empty($role) || !$user = $this->getUser($id)) {
            return false;
        }

        // Add the role to the $user['roles'] array
        $user['roles'][] = $role;

        return $this->saveUser($user);
    }
904879
public function flattenRoles($data)
    {
        $result = array();
        foreach ($data as $key => $value) {
            if (substr($key, 0, 4) === 'ROLE') {
                $result[$key] = $key;
            }
            if (is_array($value)) {
                $tmpresult = $this->flattenRoles($value);
                if (count($tmpresult) > 0) {
                    $result = array_merge($result, $tmpresult);
                }
            } else {
                $result[$value] = $value;
            }
        }

        return array_unique($result);
    }
1100152
protected function allows($roles, $resources = null)
    {
        $roles = is_array($roles) ? $roles : [$roles];
        foreach ($roles as $role) {
            if (!$role) {
                continue;
            }
            if (!$this->hasRole($role)) {
                $this->addRole($role, 'LOGGED');
            }
            $this->allow($role, $resources);
        }
        return $this;
    }
406805
public function setRoles(Collection $roles)
    {
        $this->roles->clear();
        foreach ($roles as $role) {
            $this->roles[] = $role;
        }
    }
934541
public function attachRoles($roles)
    {
        if ($roles instanceof Role) {
            $roles = [$roles->getKey()];
        }

        $this->roles()->sync($roles, false);

        unset($this->relations['roles']);

        return $this;
    }