3 final class HeraldConditionResult
4 extends HeraldTranscriptResult
{
6 const RESULT_MATCHED
= 'matched';
7 const RESULT_FAILED
= 'failed';
8 const RESULT_OBJECT_STATE
= 'object-state';
9 const RESULT_INVALID
= 'invalid';
10 const RESULT_RECURSION
= 'recursion';
11 const RESULT_EXCEPTION
= 'exception';
12 const RESULT_UNKNOWN
= 'unknown';
14 public static function newFromResultCode($result_code) {
15 return id(new self())->setResultCode($result_code);
18 public static function newFromResultMap(array $map) {
19 return id(new self())->loadFromResultMap($map);
22 public function getIsMatch() {
23 return ($this->getSpecificationProperty('match') === true);
26 public function newDetailsView(PhabricatorUser
$viewer) {
27 switch ($this->getResultCode()) {
28 case self
::RESULT_OBJECT_STATE
:
29 $reason = $this->getDataProperty('reason');
30 $details = HeraldStateReasons
::getExplanation($reason);
32 case self
::RESULT_INVALID
:
33 case self
::RESULT_EXCEPTION
:
34 $error_class = $this->getDataProperty('exception.class');
35 $error_message = $this->getDataProperty('exception.message');
37 if (!strlen($error_class)) {
38 $error_class = pht('Unknown Error');
41 switch ($error_class) {
42 case 'HeraldInvalidConditionException':
43 $error_class = pht('Invalid Condition');
47 if (!strlen($error_message)) {
49 'An unknown error occurred while evaluating this condition. No '.
50 'additional information is available.');
55 phutil_tag('strong', array(), $error_class),
56 phutil_escape_html_newlines($error_message));
66 protected function newResultSpecificationMap() {
68 self
::RESULT_MATCHED
=> array(
71 'color.icon' => 'green',
72 'name' => pht('Passed'),
74 self
::RESULT_FAILED
=> array(
77 'color.icon' => 'red',
78 'name' => pht('Failed'),
80 self
::RESULT_OBJECT_STATE
=> array(
83 'color.icon' => 'indigo',
84 'name' => pht('Forbidden'),
86 self
::RESULT_INVALID
=> array(
88 'icon' => 'fa-exclamation-triangle',
89 'color.icon' => 'yellow',
90 'name' => pht('Invalid'),
92 self
::RESULT_RECURSION
=> array(
94 'icon' => 'fa-exclamation-triangle',
95 'color.icon' => 'red',
96 'name' => pht('Recursion'),
98 self
::RESULT_EXCEPTION
=> array(
100 'icon' => 'fa-exclamation-triangle',
101 'color.icon' => 'red',
102 'name' => pht('Exception'),
104 self
::RESULT_UNKNOWN
=> array(
106 'icon' => 'fa-question',
107 'color.icon' => 'grey',
108 'name' => pht('Unknown'),