forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPhabricatorQueryOrderItem.php
61 lines (50 loc) · 1.44 KB
/
PhabricatorQueryOrderItem.php
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* Structural class representing one item in an order vector.
*
* See @{class:PhabricatorQueryOrderVector} for discussion of order vectors.
* This represents one item in an order vector, like "id". When combined with
* the other items in the vector, a complete ordering (like "name, id") is
* described.
*
* Construct an item using @{method:newFromScalar}:
*
* $item = PhabricatorQueryOrderItem::newFromScalar('id');
*
* This class is primarily internal to the query infrastructure, and most
* application code should not need to interact with it directly.
*/
final class PhabricatorQueryOrderItem extends Phobject {
private $orderKey;
private $isReversed;
private function __construct() {
// <private>
}
public static function newFromScalar($scalar) {
// If the string is something like "-id", strip the "-" off and mark it
// as reversed.
$is_reversed = false;
if (!strncmp($scalar, '-', 1)) {
$is_reversed = true;
$scalar = substr($scalar, 1);
}
$item = new PhabricatorQueryOrderItem();
$item->orderKey = $scalar;
$item->isReversed = $is_reversed;
return $item;
}
public function getIsReversed() {
return $this->isReversed;
}
public function getOrderKey() {
return $this->orderKey;
}
public function getAsScalar() {
if ($this->getIsReversed()) {
$prefix = '-';
} else {
$prefix = '';
}
return $prefix.$this->getOrderKey();
}
}