Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/storage/transcript/HeraldConditionResult.php
12262 views
1
<?php
2
3
final class HeraldConditionResult
4
extends HeraldTranscriptResult {
5
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';
13
14
public static function newFromResultCode($result_code) {
15
return id(new self())->setResultCode($result_code);
16
}
17
18
public static function newFromResultMap(array $map) {
19
return id(new self())->loadFromResultMap($map);
20
}
21
22
public function getIsMatch() {
23
return ($this->getSpecificationProperty('match') === true);
24
}
25
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);
31
break;
32
case self::RESULT_INVALID:
33
case self::RESULT_EXCEPTION:
34
$error_class = $this->getDataProperty('exception.class');
35
$error_message = $this->getDataProperty('exception.message');
36
37
if (!strlen($error_class)) {
38
$error_class = pht('Unknown Error');
39
}
40
41
switch ($error_class) {
42
case 'HeraldInvalidConditionException':
43
$error_class = pht('Invalid Condition');
44
break;
45
}
46
47
if (!strlen($error_message)) {
48
$error_message = pht(
49
'An unknown error occurred while evaluating this condition. No '.
50
'additional information is available.');
51
}
52
53
$details = pht(
54
'%s: %s',
55
phutil_tag('strong', array(), $error_class),
56
phutil_escape_html_newlines($error_message));
57
break;
58
default:
59
$details = null;
60
break;
61
}
62
63
return $details;
64
}
65
66
protected function newResultSpecificationMap() {
67
return array(
68
self::RESULT_MATCHED => array(
69
'match' => true,
70
'icon' => 'fa-check',
71
'color.icon' => 'green',
72
'name' => pht('Passed'),
73
),
74
self::RESULT_FAILED => array(
75
'match' => false,
76
'icon' => 'fa-times',
77
'color.icon' => 'red',
78
'name' => pht('Failed'),
79
),
80
self::RESULT_OBJECT_STATE => array(
81
'match' => null,
82
'icon' => 'fa-ban',
83
'color.icon' => 'indigo',
84
'name' => pht('Forbidden'),
85
),
86
self::RESULT_INVALID => array(
87
'match' => null,
88
'icon' => 'fa-exclamation-triangle',
89
'color.icon' => 'yellow',
90
'name' => pht('Invalid'),
91
),
92
self::RESULT_RECURSION => array(
93
'match' => null,
94
'icon' => 'fa-exclamation-triangle',
95
'color.icon' => 'red',
96
'name' => pht('Recursion'),
97
),
98
self::RESULT_EXCEPTION => array(
99
'match' => null,
100
'icon' => 'fa-exclamation-triangle',
101
'color.icon' => 'red',
102
'name' => pht('Exception'),
103
),
104
self::RESULT_UNKNOWN => array(
105
'match' => null,
106
'icon' => 'fa-question',
107
'color.icon' => 'grey',
108
'name' => pht('Unknown'),
109
),
110
);
111
}
112
113
}
114
115