@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
3abstract class HeraldTranscriptResult
4 extends Phobject {
5
6 private $resultCode;
7 private $resultData = array();
8
9 final protected function setResultCode($result_code) {
10 $this->resultCode = $result_code;
11 return $this;
12 }
13
14 final protected function loadFromResultMap(array $map) {
15 $result_code = idx($map, 'code');
16 $result_data = idx($map, 'data', array());
17
18 $this
19 ->setResultCode($result_code)
20 ->setResultData($result_data);
21
22 return $this;
23 }
24
25 final public function getResultCode() {
26 return $this->resultCode;
27 }
28
29 final protected function getResultData() {
30 return $this->resultData;
31 }
32
33 final public function setResultData(array $result_data) {
34 $this->resultData = $result_data;
35 return $this;
36 }
37
38 final public function getIconIcon() {
39 return $this->getSpecificationProperty('icon');
40 }
41
42 final public function getIconColor() {
43 return $this->getSpecificationProperty('color.icon');
44 }
45
46 final public function getName() {
47 return $this->getSpecificationProperty('name');
48 }
49
50 abstract public function newDetailsView(PhabricatorUser $viewer);
51
52 final protected function getDataProperty($key, $default = null) {
53 $data = $this->getResultData();
54 return idx($data, $key, $default);
55 }
56
57 final public function newResultMap() {
58 return array(
59 'code' => $this->getResultCode(),
60 'data' => $this->getResultData(),
61 );
62 }
63
64 final protected function getSpecificationProperty($key) {
65 $map = $this->getResultSpecification($this->getResultCode());
66 return $map[$key];
67 }
68
69 final protected function getResultSpecification($result_code) {
70 $map = $this->newResultSpecificationMap();
71
72 if (!isset($map[$result_code])) {
73 throw new Exception(
74 pht(
75 'Result code "%s" is unknown.',
76 $result_code));
77 }
78
79 return $map[$result_code];
80 }
81
82 abstract protected function newResultSpecificationMap();
83
84 final protected function newErrorView($error_class, $error_message) {
85 return pht(
86 '%s: %s',
87 phutil_tag('strong', array(), $error_class),
88 phutil_escape_html_newlines($error_message));
89 }
90
91}