Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / infrastructure / status / PhabricatorObjectStatus.php
blob27dec48dc957e10275c3a69498b43e0f97131e17
1 <?php
3 abstract class PhabricatorObjectStatus
4 extends Phobject {
6 private $key;
7 private $properties;
9 protected function __construct($key = null, array $properties = array()) {
10 $this->key = $key;
11 $this->properties = $properties;
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));
22 return $this->properties[$key];
25 public function getKey() {
26 return $this->key;
29 public function getIcon() {
30 return $this->getStatusProperty('icon');
33 public function getDisplayName() {
34 return $this->getStatusProperty('name');
37 public function getColor() {
38 return $this->getStatusProperty('color');
41 protected function getStatusSpecification($status) {
42 $map = self::getStatusSpecifications();
43 if (isset($map[$status])) {
44 return $map[$status];
47 return array(
48 'key' => $status,
49 'name' => pht('Unknown ("%s")', $status),
50 'icon' => 'fa-question-circle',
51 'color' => 'indigo',
52 ) + $this->newUnknownStatusSpecification($status);
55 protected function getStatusSpecifications() {
56 $map = $this->newStatusSpecifications();
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".'));
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));
72 $result[$key] = $item;
75 return $result;
78 abstract protected function newStatusSpecifications();
80 protected function newUnknownStatusSpecification($status) {
81 return array();