public function sort(array $sort = null) {
        if ($sort === null) {
            return $this->sort;
        }

        $sortData = [];

        foreach ($sort as $field) {
            $field = trim($field);
            $dir = 'asc';

            if (empty($field)) {
                throw new RuntimeException('Badly formatted sort', 400);
            }

            if (strpos($field, ':') !== false) {
                list($fieldName, $dir) = explode(':', $field);

                if ($dir !== 'asc' && $dir !== 'desc') {
                    throw new RuntimeException('Invalid sort value: ' . $field, 400);
                }

                $field = $fieldName;
            }

            $sortData[] = [
                'field' => $field,
                'sort' => $dir,
            ];
        }

        $this->sort = $sortData;

        return $this;
    }