-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDirection.php
More file actions
40 lines (35 loc) · 977 Bytes
/
Copy pathDirection.php
File metadata and controls
40 lines (35 loc) · 977 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
declare(strict_types=1);
namespace TinyBlocks\HttpQuery;
/**
* Direction applied to a single sort field, backed by its canonical token.
*/
enum Direction: string
{
case ASCENDING = 'asc';
case DESCENDING = 'desc';
/**
* Returns the prefix marking the direction in a sort expression.
*
* @return string An empty string when ascending, a leading minus when descending.
*/
public function prefix(): string
{
return match ($this) {
Direction::ASCENDING => '',
Direction::DESCENDING => '-'
};
}
/**
* Returns the strict comparison operator that seeks past the cursor in this direction.
*
* @return string A greater-than sign when ascending, a less-than sign when descending.
*/
public function seekOperator(): string
{
return match ($this) {
Direction::ASCENDING => '>',
Direction::DESCENDING => '<'
};
}
}