@param Role|string $role

@throws \InvalidArgumentException

@return Role
977680
public function get($role)
    {
        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($role)) {
            throw new \InvalidArgumentException('Role "'.$roleName.'" not found');
        }

        return $this->roles[$roleName];
    }
1254277
public function setRoles(array $roles)
    {
        $this->roleIdentifiers = [];
        $this->roles = [];
        foreach ($roles as $role) {
            if (!$role instanceof Role) {
                throw new \InvalidArgumentException(sprintf('setRoles() only accepts an array of %s instances, given: "%s"', Role::class, gettype($role)), 1397125997);
            }
            $this->addRole($role);
        }
    }
55962
public static function mapLTIRole2TaoRole($role)
    {
        $taoRole = null;
        if (filter_var($role, FILTER_VALIDATE_URL)) {
            // url found
            $taoRole = new core_kernel_classes_Resource($role);
        } else {
            // if not fully qualified prepend LIS context role NS
            if (strtolower(substr($role, 0, 4)) !== 'urn:') {
                $role = self::LIS_CONTEXT_ROLE_NAMESPACE . $role;
            }
            list ($prefix, $nid, $nss) = explode(':', $role, 3);
            if ($nid != 'lti') {
                common_Logger::w('Non LTI URN ' . $role . ' passed via LTI');
            }
            $urn = 'urn:' . strtolower($nid) . ':' . $nss;

            // search for fitting role
            $class = new core_kernel_classes_Class(LtiRoles::CLASS_URI);
            $cand = $class->searchInstances(array(
                LtiRoles::PROPERTY_URN => $urn
            ));
            if (count($cand) > 1) {
                throw new common_exception_Error('Multiple instances share the URN ' . $urn);
            }
            if (count($cand) == 1) {
                $taoRole = current($cand);
            } else {
                common_Logger::w('Unknown LTI role with urn: ' . $urn);
            }
        }
        if (!is_null($taoRole) && $taoRole->exists()) {
            return $taoRole->getUri();
        } else {
            return null;
        }
    }
637397
final protected function addRole(object $data, AbstractRole $role): BoundedRoleInterface
    {
        return new class ($role, $data) implements BoundedRoleInterface
        {
            use DelegatorTrait;

            public function __construct(AbstractRole $role, object $data)
            {
                if (false === $role->supports($data)) {
                    throw new InvalidArgumentException(
                        sprintf(
                            'Role "%s" does not support for current data',
                            get_class($role)
                        )
                    );
                }

                $this->attach($this->invoke($role, 'attach', $data));
            }

            /**
             * Extract data from bounded roles.
             *
             * @return object
             */
            public function extract(): object
            {
                return $this->invoke($this->getInstance(), 'extract');
            }

            /**
             * Invoke closure method from role.
             *
             * @param AbstractRole $role
             * @param string       $method
             * @param array        ...$args
             *
             * @return mixed
             */
            private function invoke(AbstractRole $role, string $method, ...$args)
            {
                $method = new ReflectionMethod(get_class($role), $method);
                $method->setAccessible(true);

                return $method->invoke($role, ...$args);
            }
        };
    }
395801
public function createRole(Role $role)
    {
        try {
            return $this->innerGateway->createRole($role);
        } catch (DBALException $e) {
            throw new RuntimeException('Database error', 0, $e);
        } catch (PDOException $e) {
            throw new RuntimeException('Database error', 0, $e);
        }
    }
1022892
public function hasRole(Role $role)
    {
        $this->initializeRoles();
        return array_key_exists($role->getIdentifier(), $this->roles);
    }
1042402
public function create(Role $role)
    {
        $this->authorize(UsersPolicy::PERMISSION_CREATE);

        $roles = $role->all();

        $this->setTitle($title = trans('auth::users.titles.create-user'));
        $this->addBreadcrumb($title);

        return $this->view('admin.users.create', compact('roles'));
    }
416935
public function makeRoleLockAware($role)
    {
        $role = $this->convertRoleToObject($role);
        $lock = $this->role($role);

        $role->setLock($lock);

        return $role;
    }
197854
public function getRole($role = null)
    {
        /* @var $roleItem RoleInterface */
        foreach ($this->roles as $roleItem) {
            if ($role == $roleItem->getRole()) {
                return $roleItem;
            }
        }

        return null;
    }
1026472
public function prune($role = null)
    {
        if ($role) {
            $this->addUsingAlias(RoleTableMap::COL_ID, $role->getId(), Criteria::NOT_EQUAL);
        }

        return $this;
    }
1243768
public function setRoles($roles)
    {
        $allowedValues = $this->getRolesAllowableValues();
        if (!is_null($roles) && array_diff($roles, $allowedValues)) {
            throw new \InvalidArgumentException(
                sprintf(
                    "Invalid value for 'roles', must be one of '%s'",
                    implode("', '", $allowedValues)
                )
            );
        }
        $this->container['roles'] = $roles;

        return $this;
    }
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;
	}
129435
public function removeRole($role)
    {
        $this->roles()->detach($this->getStoredRole($role));

        $this->load('roles');

        return $this;
    }
1052253
public function setRole($role)
    {
        if ( ! in_array($role, [self::ROLE_ADMIN, self::ROLE_EDITOR, self::ROLE_USER]))
            throw new \Exception('Unknown role `' . $role . '`');

        $this->role = $role;

        return $this;
    }
124019
public static function invalidRoleInstance($role)
    {
        return new self(
            sprintf('Invalid role of type "%s" provided', is_object($role) ? get_class($role) : gettype($role))
        );
    }
760889
public function addBelongTo(RoleInterface $role)
    {
        $name = $role->getType();
        $id = $role->getId();

        if (!isset($this->belongTo[$name][$id])) {
            if (!isset($this->belongTo[$name])) {
                $this->belongTo[$name] = [];
            }

            $this->belongTo[$name][$id] = $role;
        }

        return $this;
    }
1281147
public function addRole($role)
    {
        $role = strtoupper($role);
        if (static::ROLE_DEFAULT === $role) {
            return $this;
        }

        if (!$this->hasRole($role)) {
            $this->roles[] = $role;
        }

        return $this;
    }