@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
at upstream/main 173 lines 4.0 kB view raw
1<?php 2 3final class DiffusionCommitAuditStatus extends Phobject { 4 5 private $key; 6 private $spec = array(); 7 8 const NONE = 'none'; 9 const NEEDS_AUDIT = 'needs-audit'; 10 const CONCERN_RAISED = 'concern-raised'; 11 const PARTIALLY_AUDITED = 'partially-audited'; 12 const AUDITED = 'audited'; 13 const NEEDS_VERIFICATION = 'needs-verification'; 14 15 public static function newModernKeys(array $values) { 16 $map = self::getMap(); 17 18 $modern = array(); 19 foreach ($map as $key => $spec) { 20 if (isset($spec['legacy'])) { 21 $modern[$spec['legacy']] = $key; 22 } 23 } 24 25 foreach ($values as $key => $value) { 26 $values[$key] = idx($modern, $value, $value); 27 } 28 29 return $values; 30 } 31 32 public static function newForStatus($status) { 33 $result = new self(); 34 35 $result->key = $status; 36 37 $map = self::getMap(); 38 if (isset($map[$status])) { 39 $result->spec = $map[$status]; 40 } 41 42 return $result; 43 } 44 45 public function getKey() { 46 return $this->key; 47 } 48 49 public function getIcon() { 50 return idx($this->spec, 'icon'); 51 } 52 53 public function getColor() { 54 return idx($this->spec, 'color'); 55 } 56 57 public function getAnsiColor() { 58 return idx($this->spec, 'color.ansi'); 59 } 60 61 public function getName() { 62 return idx($this->spec, 'name', pht('Unknown ("%s")', $this->key)); 63 } 64 65 public function isNoAudit() { 66 return ($this->key == self::NONE); 67 } 68 69 public function isNeedsAudit() { 70 return ($this->key == self::NEEDS_AUDIT); 71 } 72 73 public function isConcernRaised() { 74 return ($this->key == self::CONCERN_RAISED); 75 } 76 77 public function isNeedsVerification() { 78 return ($this->key == self::NEEDS_VERIFICATION); 79 } 80 81 public function isPartiallyAudited() { 82 return ($this->key == self::PARTIALLY_AUDITED); 83 } 84 85 public function isAudited() { 86 return ($this->key == self::AUDITED); 87 } 88 89 public function getIsClosed() { 90 return idx($this->spec, 'closed'); 91 } 92 93 public static function getOpenStatusConstants() { 94 $constants = array(); 95 foreach (self::getMap() as $key => $map) { 96 if (!$map['closed']) { 97 $constants[] = $key; 98 } 99 } 100 return $constants; 101 } 102 103 public static function newOptions() { 104 $map = self::getMap(); 105 return ipull($map, 'name'); 106 } 107 108 public static function newDeprecatedOptions() { 109 $map = self::getMap(); 110 111 $results = array(); 112 foreach ($map as $key => $spec) { 113 if (isset($spec['legacy'])) { 114 $results[$spec['legacy']] = $key; 115 } 116 } 117 118 return $results; 119 } 120 121 private static function getMap() { 122 return array( 123 self::NONE => array( 124 'name' => pht('No Audits'), 125 'legacy' => 0, 126 'icon' => 'fa-check', 127 'color' => 'bluegrey', 128 'closed' => true, 129 'color.ansi' => null, 130 ), 131 self::NEEDS_AUDIT => array( 132 'name' => pht('Audit Required'), 133 'legacy' => 1, 134 'icon' => 'fa-exclamation-circle', 135 'color' => 'orange', 136 'closed' => false, 137 'color.ansi' => 'magenta', 138 ), 139 self::CONCERN_RAISED => array( 140 'name' => pht('Concern Raised'), 141 'legacy' => 2, 142 'icon' => 'fa-times-circle', 143 'color' => 'red', 144 'closed' => false, 145 'color.ansi' => 'red', 146 ), 147 self::PARTIALLY_AUDITED => array( 148 'name' => pht('Partially Audited'), 149 'legacy' => 3, 150 'icon' => 'fa-check-circle-o', 151 'color' => 'yellow', 152 'closed' => false, 153 'color.ansi' => 'yellow', 154 ), 155 self::AUDITED => array( 156 'name' => pht('Audited'), 157 'legacy' => 4, 158 'icon' => 'fa-check-circle', 159 'color' => 'green', 160 'closed' => true, 161 'color.ansi' => 'green', 162 ), 163 self::NEEDS_VERIFICATION => array( 164 'name' => pht('Needs Verification'), 165 'legacy' => 5, 166 'icon' => 'fa-refresh', 167 'color' => 'indigo', 168 'closed' => false, 169 'color.ansi' => 'magenta', 170 ), 171 ); 172 } 173}