Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14119284
D21564.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
7 KB
Referenced Files
None
Subscribers
None
D21564.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1662,6 +1662,7 @@
'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php',
'HeraldTranscriptPHIDType' => 'applications/herald/phid/HeraldTranscriptPHIDType.php',
'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php',
+ 'HeraldTranscriptResult' => 'applications/herald/storage/transcript/HeraldTranscriptResult.php',
'HeraldTranscriptSearchEngine' => 'applications/herald/query/HeraldTranscriptSearchEngine.php',
'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php',
'HeraldUtilityActionGroup' => 'applications/herald/action/HeraldUtilityActionGroup.php',
@@ -7794,7 +7795,7 @@
'HarbormasterBuildableAdapterInterface',
),
'HeraldCondition' => 'HeraldDAO',
- 'HeraldConditionResult' => 'Phobject',
+ 'HeraldConditionResult' => 'HeraldTranscriptResult',
'HeraldConditionTranscript' => 'Phobject',
'HeraldContentSourceField' => 'HeraldField',
'HeraldController' => 'PhabricatorController',
@@ -7905,6 +7906,7 @@
'HeraldTranscriptListController' => 'HeraldController',
'HeraldTranscriptPHIDType' => 'PhabricatorPHIDType',
'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'HeraldTranscriptResult' => 'Phobject',
'HeraldTranscriptSearchEngine' => 'PhabricatorApplicationSearchEngine',
'HeraldTranscriptTestCase' => 'PhabricatorTestCase',
'HeraldUtilityActionGroup' => 'HeraldActionGroup',
diff --git a/src/applications/herald/storage/transcript/HeraldConditionResult.php b/src/applications/herald/storage/transcript/HeraldConditionResult.php
--- a/src/applications/herald/storage/transcript/HeraldConditionResult.php
+++ b/src/applications/herald/storage/transcript/HeraldConditionResult.php
@@ -1,7 +1,7 @@
<?php
final class HeraldConditionResult
- extends Phobject {
+ extends HeraldTranscriptResult {
const RESULT_MATCHED = 'matched';
const RESULT_FAILED = 'failed';
@@ -10,61 +10,20 @@
const RESULT_EXCEPTION = 'exception';
const RESULT_UNKNOWN = 'unknown';
- private $resultCode;
- private $resultData = array();
-
- public function toMap() {
- return array(
- 'code' => $this->getResultCode(),
- 'data' => $this->getResultData(),
- );
- }
-
- public static function newFromMap(array $map) {
- $result_code = idx($map, 'code');
- $result = self::newFromResultCode($result_code);
-
- $result_data = idx($map, 'data', array());
- $result->setResultData($result_data);
-
- return $result;
- }
-
public static function newFromResultCode($result_code) {
- $map = self::getResultSpecification($result_code);
-
- $result = new self();
- $result->resultCode = $result_code;
-
- return $result;
- }
-
- public function getResultCode() {
- return $this->resultCode;
- }
-
- private function getResultData() {
- return $this->resultData;
+ return id(new self())->setResultCode($result_code);
}
- public function getIconIcon() {
- return $this->getSpecificationProperty('icon');
- }
-
- public function getIconColor() {
- return $this->getSpecificationProperty('color.icon');
+ public static function newFromResultMap(array $map) {
+ return id(new self())->loadFromResultMap($map);
}
public function getIsMatch() {
return ($this->getSpecificationProperty('match') === true);
}
- public function getName() {
- return $this->getSpecificationProperty('name');
- }
-
public function newDetailsView() {
- switch ($this->resultCode) {
+ switch ($this->getResultCode()) {
case self::RESULT_OBJECT_STATE:
$reason = $this->getDataProperty('reason');
$details = HeraldStateReasons::getExplanation($reason);
@@ -105,35 +64,7 @@
return $details;
}
- public function setResultData(array $result_data) {
- $this->resultData = $result_data;
- return $this;
- }
-
- private function getDataProperty($key) {
- $data = $this->getResultData();
- return idx($data, $key);
- }
-
- private function getSpecificationProperty($key) {
- $map = self::getResultSpecification($this->resultCode);
- return $map[$key];
- }
-
- private static function getResultSpecification($result_code) {
- $map = self::getResultSpecificationMap();
-
- if (!isset($map[$result_code])) {
- throw new Exception(
- pht(
- 'Condition result "%s" is unknown.',
- $result_code));
- }
-
- return $map[$result_code];
- }
-
- private static function getResultSpecificationMap() {
+ protected function newResultSpecificationMap() {
return array(
self::RESULT_MATCHED => array(
'match' => true,
diff --git a/src/applications/herald/storage/transcript/HeraldConditionTranscript.php b/src/applications/herald/storage/transcript/HeraldConditionTranscript.php
--- a/src/applications/herald/storage/transcript/HeraldConditionTranscript.php
+++ b/src/applications/herald/storage/transcript/HeraldConditionTranscript.php
@@ -65,7 +65,7 @@
}
public function setResult(HeraldConditionResult $result) {
- $this->resultMap = $result->toMap();
+ $this->resultMap = $result->newResultMap();
return $this;
}
@@ -73,7 +73,7 @@
$map = $this->resultMap;
if (is_array($map)) {
- $result = HeraldConditionResult::newFromMap($map);
+ $result = HeraldConditionResult::newFromResultMap($map);
} else {
$legacy_result = $this->result;
diff --git a/src/applications/herald/storage/transcript/HeraldTranscriptResult.php b/src/applications/herald/storage/transcript/HeraldTranscriptResult.php
new file mode 100644
--- /dev/null
+++ b/src/applications/herald/storage/transcript/HeraldTranscriptResult.php
@@ -0,0 +1,82 @@
+<?php
+
+abstract class HeraldTranscriptResult
+ extends Phobject {
+
+ private $resultCode;
+ private $resultData = array();
+
+ final protected function setResultCode($result_code) {
+ $this->resultCode = $result_code;
+ return $this;
+ }
+
+ final protected function loadFromResultMap(array $map) {
+ $result_code = idx($map, 'code');
+ $result_data = idx($map, 'data', array());
+
+ $this
+ ->setResultCode($result_code)
+ ->setResultData($result_data);
+
+ return $this;
+ }
+
+ final public function getResultCode() {
+ return $this->resultCode;
+ }
+
+ final protected function getResultData() {
+ return $this->resultData;
+ }
+
+ final public function setResultData(array $result_data) {
+ $this->resultData = $result_data;
+ return $this;
+ }
+
+ final public function getIconIcon() {
+ return $this->getSpecificationProperty('icon');
+ }
+
+ final public function getIconColor() {
+ return $this->getSpecificationProperty('color.icon');
+ }
+
+ final public function getName() {
+ return $this->getSpecificationProperty('name');
+ }
+
+ final protected function getDataProperty($key) {
+ $data = $this->getResultData();
+ return idx($data, $key);
+ }
+
+ final public function newResultMap() {
+ return array(
+ 'code' => $this->getResultCode(),
+ 'data' => $this->getResultData(),
+ );
+ }
+
+ final protected function getSpecificationProperty($key) {
+ $map = $this->getResultSpecification($this->getResultCode());
+ return $map[$key];
+ }
+
+ final protected function getResultSpecification($result_code) {
+ $map = $this->newResultSpecificationMap();
+
+ if (!isset($map[$result_code])) {
+ throw new Exception(
+ pht(
+ 'Result code "%s" is unknown.',
+ $result_code));
+ }
+
+ return $map[$result_code];
+ }
+
+ abstract protected function newResultSpecificationMap();
+
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sat, Nov 30, 4:29 AM (19 h, 55 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6807774
Default Alt Text
D21564.diff (7 KB)
Attached To
Mode
D21564: Lift core of "HeraldConditionResult" to "HeraldTranscriptResult"
Attached
Detach File
Event Timeline
Log In to Comment