@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
3final class HeraldRuleTranscript extends Phobject {
4
5 protected $ruleID;
6 protected $ruleResultMap;
7 protected $ruleName;
8 protected $ruleOwner;
9
10 // See T13586. This no longer has readers, but was written by older versions
11 // of Herald. It contained a human readable English-language description of
12 // the outcome of rule evaluation and was superseded by "HeraldRuleResult".
13 protected $reason;
14
15 // See T13586. Older transcripts store a boolean "true", a boolean "false",
16 // or the string "forbidden" here.
17 protected $result;
18
19 public function setRuleID($rule_id) {
20 $this->ruleID = $rule_id;
21 return $this;
22 }
23
24 public function getRuleID() {
25 return $this->ruleID;
26 }
27
28 public function setRuleName($rule_name) {
29 $this->ruleName = $rule_name;
30 return $this;
31 }
32
33 public function getRuleName() {
34 return $this->ruleName;
35 }
36
37 public function setRuleOwner($rule_owner) {
38 $this->ruleOwner = $rule_owner;
39 return $this;
40 }
41
42 public function getRuleOwner() {
43 return $this->ruleOwner;
44 }
45
46 public function setRuleResult(HeraldRuleResult $result) {
47 $this->ruleResultMap = $result->newResultMap();
48 return $this;
49 }
50
51 public function getRuleResult() {
52 $map = $this->ruleResultMap;
53
54 if (is_array($map)) {
55 $result = HeraldRuleResult::newFromResultMap($map);
56 } else {
57 $legacy_result = $this->result;
58
59 $result_data = array();
60
61 if ($legacy_result === 'forbidden') {
62 $result_code = HeraldRuleResult::RESULT_OBJECT_STATE;
63 $result_data = array(
64 'reason' => $this->reason,
65 );
66 } else if ($legacy_result === true) {
67 $result_code = HeraldRuleResult::RESULT_ANY_MATCHED;
68 } else if ($legacy_result === false) {
69 $result_code = HeraldRuleResult::RESULT_ANY_FAILED;
70 } else {
71 $result_code = HeraldRuleResult::RESULT_UNKNOWN;
72 }
73
74 $result = HeraldRuleResult::newFromResultCode($result_code)
75 ->setResultData($result_data);
76 }
77
78 return $result;
79 }
80
81}