mirror of
https://github.com/shlinkio/shlink.git
synced 2026-03-11 17:44:44 +08:00
Add more named constructors to Ordering class
This commit is contained in:
@@ -6,7 +6,9 @@ namespace Shlinkio\Shlink\Core\Model;
|
||||
|
||||
final readonly class Ordering
|
||||
{
|
||||
private const DEFAULT_DIR = 'ASC';
|
||||
private const DESC_DIR = 'DESC';
|
||||
private const ASC_DIR = 'ASC';
|
||||
private const DEFAULT_DIR = self::ASC_DIR;
|
||||
|
||||
private function __construct(public ?string $field, public string $direction)
|
||||
{
|
||||
@@ -23,6 +25,16 @@ final readonly class Ordering
|
||||
|
||||
public static function none(): self
|
||||
{
|
||||
return self::fromTuple([null, null]);
|
||||
return new self(null, self::DEFAULT_DIR);
|
||||
}
|
||||
|
||||
public static function fromFieldAsc(string $field): self
|
||||
{
|
||||
return new self($field, self::ASC_DIR);
|
||||
}
|
||||
|
||||
public static function fromFieldDesc(string $field): self
|
||||
{
|
||||
return new self($field, self::DESC_DIR);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ final class TagsParams extends AbstractInfinitePaginableListParams
|
||||
{
|
||||
return new self(
|
||||
$query['searchTerm'] ?? null,
|
||||
Ordering::fromTuple(isset($query['orderBy']) ? parseOrderBy($query['orderBy']) : [null, null]),
|
||||
isset($query['orderBy']) ? Ordering::fromTuple(parseOrderBy($query['orderBy'])) : Ordering::none(),
|
||||
isset($query['page']) ? (int) $query['page'] : null,
|
||||
isset($query['itemsPerPage']) ? (int) $query['itemsPerPage'] : null,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user