Remove product literal strings in "pht()", part 18
[phabricator.git] / src / infrastructure / query / order / PhabricatorQueryOrderItem.php
blob474b495e481df87fcabbf21928d9f42347d3cb42
1 <?php
3 /**
4 * Structural class representing one item in an order vector.
6 * See @{class:PhabricatorQueryOrderVector} for discussion of order vectors.
7 * This represents one item in an order vector, like "id". When combined with
8 * the other items in the vector, a complete ordering (like "name, id") is
9 * described.
11 * Construct an item using @{method:newFromScalar}:
13 * $item = PhabricatorQueryOrderItem::newFromScalar('id');
15 * This class is primarily internal to the query infrastructure, and most
16 * application code should not need to interact with it directly.
18 final class PhabricatorQueryOrderItem extends Phobject {
20 private $orderKey;
21 private $isReversed;
23 private function __construct() {
24 // <private>
27 public static function newFromScalar($scalar) {
28 // If the string is something like "-id", strip the "-" off and mark it
29 // as reversed.
30 $is_reversed = false;
31 if (!strncmp($scalar, '-', 1)) {
32 $is_reversed = true;
33 $scalar = substr($scalar, 1);
36 $item = new PhabricatorQueryOrderItem();
37 $item->orderKey = $scalar;
38 $item->isReversed = $is_reversed;
40 return $item;
43 public function getIsReversed() {
44 return $this->isReversed;
47 public function getOrderKey() {
48 return $this->orderKey;
51 public function getAsScalar() {
52 if ($this->getIsReversed()) {
53 $prefix = '-';
54 } else {
55 $prefix = '';
58 return $prefix.$this->getOrderKey();