Return scopes with order values
@param array $scopes
@return array
963231
protected function _getScopes($scopes = [])
    {
        if ($scopes) {
            $returnScopes = [];
            foreach ($scopes as $scope) {
                $returnScopes[$scope] = $this->_scopes[$scope];
            }
            return $returnScopes;
        } else {
            return $this->_scopes;
        }
    }
284985
public static function scopes()
    {
        return collect(static::$scopes)->map(function ($description, $id) {
            return new Scope($id, $description);
        })->values();
    }
1279220
public function getScopes()
    {
        if (!isset($this->_scopes)) {
            $this->_scopes = clone $this->getService('com:components.domain.entityset.scope');
        }

        return $this->_scopes;
    }
1239507
public function all($scope = null)
    {
        if ($scope === null) {
            return array_values($this->messages);
        }

        $messages = array();
        foreach ($this->messages as $message) {
            if ($message['scope'] === $scope) {
                $messages[] = $message;
            }
        }

        return $messages;
    }
394348
public static function sort(array $versions) : array
    {
        usort(
            $versions,
            function (Version $a, Version $b) {
                return VersionComparator::compare($a, $b);
            }
        );

        return $versions;
    }
319586
public function scope($scope)
	{
		$scope = (new Scope())->scope($scope);

		$this->scopes[] = $scope;
		return $scope;
	}
553826
public function getNextSortValue(array $scope = []): int
    {
        $query = $this->_table->query();
        $scope = Hash::merge($this->getConfig('scope'), $scope);
        if (!empty($scope)) {
            $query->where($scope);
        }
        $query->select([
            'maxSort' => $query->func()->max($this->getConfig('sortField')),
        ]);
        $res = $query->enableHydration(false)->first();
        if (empty($res)) {
            return 1;
        }

        return ($res['maxSort'] + 1);
    }
1249032
protected function parseScopeArray(array $scopes)
    {
        $parsedScopes = [];

        foreach ($scopes as $scope) {
            if (is_string($scope) && $scope != '') {
                $parsedScopes[] = $scope;
            } else if ($scope instanceof IScope) {
                $parsedScopes[] =  $scope->getId();
            } else {
                throw new \InvalidArgumentException('Scopes has to be array of strings or OAuth2\Storage\IScope instances.');
            }
        }

        return $parsedScopes;
    }
1298145
public function withoutGlobalScopes(array $scopes = null)
    {
        $this->model = $this->model->withoutGlobalScopes($scopes);
        return $this;
    }
457291
protected function convertScopesToCriteriaArray()
    {
        $scopes = [];

        foreach ($this->scopes as $scope) {

            if (array_key_exists($scope, $this->scopeParameters) && ! empty($this->scopeParameters[ $scope ])) {

                $scopes[] = [ $scope, $this->scopeParameters[ $scope ] ];
                continue;
            }

            $scopes[] = [ $scope, [] ];
        }

        return $scopes;
    }
1361497
protected function getOAuthTokenHeader($scopes) {
    if ($this->anonymous) {
      return [];
    }

    try {
      $token = AppIdentityService::getAccessToken($scopes);
      return ["Authorization" => sprintf(self::OAUTH_TOKEN_FORMAT,
                                         $token['access_token'])];
    } catch (AppIdentityException $e) {
      return false;
    }
  }
754454
protected function formatScopes($unformated = [])
    {
        $scopes = [];
        foreach ($unformated as $scope) {
            if ($scope instanceof ScopeEntity) {
                $scopes[$scope->getId()] = $scope;
            }
        }

        return $scopes;
    }
549838
public function scopes(array $scopes)
    {
        $builder = $this;

        foreach ($scopes as $scope => $parameters) {
            // If the scope key is an integer, then the scope was passed as the value and
            // the parameter list is empty, so we will format the scope name and these
            // parameters here. Then, we'll be ready to call the scope on the model.
            if (is_int($scope)) {
                [$scope, $parameters] = [$parameters, []];
            }

            // Next we'll pass the scope callback to the callScope method which will take
            // care of grouping the "wheres" properly so the logical order doesn't get
            // messed up when adding scopes. Then we'll return back out the builder.
            $builder = $builder->callScope(
                [$this->model, 'scope'.ucfirst($scope)],
                (array) $parameters
            );
        }

        return $builder;
    }
494492
protected function _order($fields)
    {
        $direction = 'ASC';

        $result = [];
        foreach ($fields as $field => $value) {
            if (!is_int($field)) {
                $result[$field] = $value;
                continue;
            }
            if (preg_match('/^(.*?)\s+((?:a|de)sc)$/i', $value, $match)) {
                $value = $match[1];
                $dir = $match[2];
            } else {
                $dir = $direction;
            }
            $result[$value] = $dir;
        }
        return $result;
    }
788250
public function withoutGlobalScopes(array $scopes = null)
    {
        if (! is_array($scopes)) {
            $scopes = array_keys($this->scopes);
        }

        foreach ($scopes as $scope) {
            $this->withoutGlobalScope($scope);
        }

        return $this;
    }
1090436
protected function getRequestOptions(array $defaults = []) {

        $defaults = array_merge($this->getDefaultOptions(), $defaults);

        $page = $this->hasRequestParameter('page') ? $this->getRequestParameter('page') : $defaults['page'];
        $rows = $this->hasRequestParameter('rows') ? $this->getRequestParameter('rows') : $defaults['rows'];
        $sortBy = $this->hasRequestParameter('sortby') ? $this->getRequestParameter('sortby') : $defaults['sortby'];
        $sortOrder = $this->hasRequestParameter('sortorder') ? $this->getRequestParameter('sortorder') : $defaults['sortorder'];
        $filter = $this->hasRequestParameter('filter') ? $this->getRequestParameter('filter') : $defaults['filter'];
        $filterquery = $this->hasRequestParameter('filterquery') ? $this->getRequestParameter('filterquery') : $defaults['filter'];
        $periodStart = $this->hasRequestParameter('periodStart') ? $this->getRequestParameter('periodStart') : $defaults['periodStart'];
        $periodEnd = $this->hasRequestParameter('periodEnd') ? $this->getRequestParameter('periodEnd') : $defaults['periodEnd'];
        $detailed = $this->hasRequestParameter('detailed') ? $this->getRequestParameter('detailed') : 'false';
        $detailed = filter_var($detailed, FILTER_VALIDATE_BOOLEAN);

        return array(
            'page' => $page,
            'rows' => $rows,
            'sortBy' => $sortBy,
            'sortOrder' => $sortOrder,
            'filter' => $filter ? $filter : $filterquery,
            'periodStart' => $periodStart,
            'detailed' => $detailed,
            'periodEnd' => $periodEnd
        );

    }
423328
public function allSoftware($scopes = []) {
        if (!$this->id) {
            throw new Exception("The server has no ID, can\'t get software");
        }

        $software = new Software($this->patrol);

        $software->defaults([
            'server_id' => $this->id
        ]);

        return $software->all($scopes);
    }