forked from phacility/phabricator
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathPhabricatorObjectStatus.php
84 lines (65 loc) · 1.85 KB
/
PhabricatorObjectStatus.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<?php
abstract class PhabricatorObjectStatus
extends Phobject {
private $key;
private $properties;
protected function __construct($key = null, array $properties = array()) {
$this->key = $key;
$this->properties = $properties;
}
protected function getStatusProperty($key) {
if (!array_key_exists($key, $this->properties)) {
throw new Exception(
pht(
'Attempting to access unknown status property ("%s").',
$key));
}
return $this->properties[$key];
}
public function getKey() {
return $this->key;
}
public function getIcon() {
return $this->getStatusProperty('icon');
}
public function getDisplayName() {
return $this->getStatusProperty('name');
}
public function getColor() {
return $this->getStatusProperty('color');
}
protected function getStatusSpecification($status) {
$map = self::getStatusSpecifications();
if (isset($map[$status])) {
return $map[$status];
}
return array(
'key' => $status,
'name' => pht('Unknown ("%s")', $status),
'icon' => 'fa-question-circle',
'color' => 'indigo',
) + $this->newUnknownStatusSpecification($status);
}
protected function getStatusSpecifications() {
$map = $this->newStatusSpecifications();
$result = array();
foreach ($map as $item) {
if (!array_key_exists('key', $item)) {
throw new Exception(pht('Status specification has no "key".'));
}
$key = $item['key'];
if (isset($result[$key])) {
throw new Exception(
pht(
'Multiple status definitions share the same key ("%s").',
$key));
}
$result[$key] = $item;
}
return $result;
}
abstract protected function newStatusSpecifications();
protected function newUnknownStatusSpecification($status) {
return array();
}
}