@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * Structural class representing one item in an order vector.
5 *
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.
10 *
11 * Construct an item using @{method:newFromScalar}:
12 *
13 * $item = PhabricatorQueryOrderItem::newFromScalar('id');
14 *
15 * This class is primarily internal to the query infrastructure, and most
16 * application code should not need to interact with it directly.
17 */
18final class PhabricatorQueryOrderItem extends Phobject {
19
20 private $orderKey;
21 private $isReversed;
22
23 private function __construct() {
24 // <private>
25 }
26
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);
34 }
35
36 $item = new PhabricatorQueryOrderItem();
37 $item->orderKey = $scalar;
38 $item->isReversed = $is_reversed;
39
40 return $item;
41 }
42
43 public function getIsReversed() {
44 return $this->isReversed;
45 }
46
47 public function getOrderKey() {
48 return $this->orderKey;
49 }
50
51 public function getAsScalar() {
52 if ($this->getIsReversed()) {
53 $prefix = '-';
54 } else {
55 $prefix = '';
56 }
57
58 return $prefix.$this->getOrderKey();
59 }
60
61}