@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 84 lines 1.9 kB view raw
1<?php 2 3abstract class PhabricatorObjectStatus 4 extends Phobject { 5 6 private $key; 7 private $properties; 8 9 protected function __construct($key = null, array $properties = array()) { 10 $this->key = $key; 11 $this->properties = $properties; 12 } 13 14 protected function getStatusProperty($key) { 15 if (!array_key_exists($key, $this->properties)) { 16 throw new Exception( 17 pht( 18 'Attempting to access unknown status property ("%s").', 19 $key)); 20 } 21 22 return $this->properties[$key]; 23 } 24 25 public function getKey() { 26 return $this->key; 27 } 28 29 public function getIcon() { 30 return $this->getStatusProperty('icon'); 31 } 32 33 public function getDisplayName() { 34 return $this->getStatusProperty('name'); 35 } 36 37 public function getColor() { 38 return $this->getStatusProperty('color'); 39 } 40 41 protected function getStatusSpecification($status) { 42 $map = self::getStatusSpecifications(); 43 if (isset($map[$status])) { 44 return $map[$status]; 45 } 46 47 return array( 48 'key' => $status, 49 'name' => pht('Unknown ("%s")', $status), 50 'icon' => 'fa-question-circle', 51 'color' => 'indigo', 52 ) + $this->newUnknownStatusSpecification($status); 53 } 54 55 protected function getStatusSpecifications() { 56 $map = $this->newStatusSpecifications(); 57 58 $result = array(); 59 foreach ($map as $item) { 60 if (!array_key_exists('key', $item)) { 61 throw new Exception(pht('Status specification has no "key".')); 62 } 63 64 $key = $item['key']; 65 if (isset($result[$key])) { 66 throw new Exception( 67 pht( 68 'Multiple status definitions share the same key ("%s").', 69 $key)); 70 } 71 72 $result[$key] = $item; 73 } 74 75 return $result; 76 } 77 78 abstract protected function newStatusSpecifications(); 79 80 protected function newUnknownStatusSpecification($status) { 81 return array(); 82 } 83 84}