Define a sort parameter. This method will manipulate the uri of the request.
@param string $name
@param string $direction
357482
public function addOrderBy(string $name, string $direction = self::ORDER_ASC): void
    {
        $this->order[$name] = $direction;
        $this->updateUriQuery();
    }
1017147
public static function sortKeys(array $array, string $direction = 'ASC')
    {
        $direction = (strtolower($direction) === 'desc') ? SORT_DESC : SORT_ASC;
        if ($direction === SORT_ASC) {
            ksort($array);
        } else {
            krsort($array);
        }

        return $array;
    }
522230
public function sortByFieldFilter($content, $sort_by = null, $direction = 'asc') {

        if (is_a($content, 'Doctrine\Common\Collections\Collection')) {
            $content = $content->toArray();
        }

        if (!is_array($content)) {
            throw new \InvalidArgumentException('Variable passed to the sortByField filter is not an array');
        } elseif (count($content) < 1) {
            return $content;
        } elseif ($sort_by === null) {
            throw new Exception('No sort by parameter passed to the sortByField filter');
        } elseif (!self::isSortable(current($content), $sort_by)) {
            throw new Exception('Entries passed to the sortByField filter do not have the field "' . $sort_by . '"');
        } else {
            // Unfortunately have to suppress warnings here due to __get function
            // causing usort to think that the array has been modified:
            // usort(): Array was modified by the user comparison function
            @usort($content, function ($a, $b) use ($sort_by, $direction) {
                $flip = ($direction === 'desc') ? -1 : 1;

                if (is_array($a))
                    $a_sort_value = $a[$sort_by];
                else if (method_exists($a, 'get' . ucfirst($sort_by)))
                    $a_sort_value = $a->{'get' . ucfirst($sort_by)}();
                else
                    $a_sort_value = $a->$sort_by;

                if (is_array($b))
                    $b_sort_value = $b[$sort_by];
                else if (method_exists($b, 'get' . ucfirst($sort_by)))
                    $b_sort_value = $b->{'get' . ucfirst($sort_by)}();
                else
                    $b_sort_value = $b->$sort_by;

                if ($a_sort_value == $b_sort_value) {
                    return 0;
                } else if ($a_sort_value > $b_sort_value) {
                    return (1 * $flip);
                } else {
                    return (-1 * $flip);
                }
            });
        }
        return $content;
    }
854639
public function orderBy($field, $direction = 'asc')
    {
        $this->sort = $field;
        $this->sortDirection = $direction;

        return $this;
    }
1311603
public function orderBy($field, $direction = self::DESC) {
        if (is_array($field)) {
            foreach ($field as $key => $dir) {
                $this->orderBy($key, $dir);
            }

        } else if ($field === 'RAND') {
            $this->_orderBy[] = $this->func('RAND');

        } else if ($field instanceof Func) {
            $this->_orderBy[] = $field;

        } else {
            $direction = strtolower($direction);

            if ($direction != self::ASC && $direction != self::DESC) {
                throw new InvalidArgumentException(sprintf('Invalid order direction %s for field %s', $direction, $field));
            }

            $this->_orderBy[$field] = $direction;
        }

        return $this;
    }
1002420
public function sorts($sorts, $direction = self::SORT_DESC) {
		foreach($sorts as $sort) {
			$this->sort($sort, $direction);
		}
		return $this;
	}
737241
public function orderBy(string $field, int $direction = self::ASCENDING): DocumentSelector
    {
        return $this->sortBy($this->sortBy + [$field => $direction]);
    }
774848
public org.grails.datastore.mapping.query.api.Criteria order(String propertyName, String direction) {
        if (criteria == null) {
            throwRuntimeException(new IllegalArgumentException("Call to [order] with propertyName [" +
                    propertyName + "]not allowed here."));
        }
        propertyName = calculatePropertyName(propertyName);
        Order o;
        if (direction.equals(ORDER_DESCENDING)) {
            o = Order.desc(propertyName);
        }
        else {
            o = Order.asc(propertyName);
        }
        if (paginationEnabledList) {
            orderEntries.add(o);
        }
        else {
            criteria.addOrder(o);
        }
        return this;
    }
1083343
public function sort($direction)
    {
        if (strtolower($direction) === self::DIRECTION_DESC) {
            $this->scanIndexForward = false;
        } else {
            $this->scanIndexForward = true;
        }
    }
67863
final public function orderBy($orderby, $direction = '')
    {
        if (strtolower($direction) == 'random') {
            $orderby = ''; // Random results want or don't need a field name
            $direction = $this->_randomKeyword;
        } elseif (trim($direction) != '') {
            $direction = (in_array(strtoupper(trim($direction)), array('ASC', 'DESC'), TRUE)) ? ' ' . $direction : ' ASC';
        }


        if (strpos($orderby, ',') !== FALSE) {
            $temp = array();
            foreach (explode(',', $orderby) as $part) {
                $part = trim($part);
                if (!in_array($part, $this->arrayAliasedTables)) {
                    $part = $this->identifiers(trim($part));
                }
                $temp[] = $part;
            }

            $orderby = implode(', ', $temp);
        } else if ($direction != $this->_randomKeyword) {
            $orderby = $this->identifiers($orderby);
        }

        $orderbyStatement = $orderby . $direction;

        $this->arrayOrderBy[] = $orderbyStatement;
        if ($this->arrayCaching === TRUE) {
            $this->arrayCacheOrderBy[] = $orderbyStatement;
            $this->arrayCacheExists[] = 'orderby';
        }

        return $this;
    }
1205950
public function orderBy(string $key, string $direction = 'ASC'): SelectQueryBuilder
    {
        array_push($this->orderBy, [
            'key' => $key,
            'direction' => strtoupper($direction),
        ]);
        return $this;
    }
1229428
public function addRouteMiddleware(string $name): void
    {
        if (!array_key_exists($name, $this->getConfigRouteMiddlewares())) {
            throw new InvalidArgumentException('The middleware [' . $name . '] does not exists.');
        }

        $this->routeMiddlewares[] = $this->getConfigRouteMiddlewares()[$name];
    }
716832
public function scopeSort(Builder $query, $column, $direction)
    {
        if (!in_array($column, $this->sortable)) {
            return $query;
        }

        return $query->orderBy($column, $direction);
    }
138973
private function findClassType($name, $direction)
    {
        if (!isset($this->types[$direction])) {
            return;
        }

        foreach ($this->types[$direction] as $class => $type) {
            if ((class_exists($class) || interface_exists($class)) && is_a($name, $class, true)) {
                return $type;
            }
        }
    }
22801
public static function fromOptionsWithDirection(Direction $direction, OptionsInterface $options = null)
    {
        if (null === $options) {
            $options = (new static($direction))->withExceptionOnSkip(false);
        } else {
            $options = $options->withDirection($direction);
        }
        return $options;
    }
278598
public function add_sort($field, $direction = 'ASC') {
        if (!isset($this->_query_modifiers['sort'])) {
            $this->_query_modifiers['sort'] = array();
        }

        $this->_query_modifiers['sort'][$field] = $direction;
    }
8414
public function sortBy(string $field, string $direction = 'asc'): self
    {
        $this->sortBy = [$field, $direction];

        return $this;
    }