mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Lift core of "HeraldConditionResult" to "HeraldTranscriptResult"
Summary: Ref T13586. Lift the behavioral core of "HeraldConditionResult" into a new abstract base "HeraldTranscriptResult", with the intent to introduce a "HeraldRuleResult". Test Plan: - Ran Herald rules, reviewed transcripts. - This change should have no behavioral effect. Maniphest Tasks: T13586 Differential Revision: https://secure.phabricator.com/D21564
This commit is contained in:
parent
e77ae13d5c
commit
b047653e53
4 changed files with 93 additions and 78 deletions
|
@ -1662,6 +1662,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php',
|
'HeraldTranscriptListController' => 'applications/herald/controller/HeraldTranscriptListController.php',
|
||||||
'HeraldTranscriptPHIDType' => 'applications/herald/phid/HeraldTranscriptPHIDType.php',
|
'HeraldTranscriptPHIDType' => 'applications/herald/phid/HeraldTranscriptPHIDType.php',
|
||||||
'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php',
|
'HeraldTranscriptQuery' => 'applications/herald/query/HeraldTranscriptQuery.php',
|
||||||
|
'HeraldTranscriptResult' => 'applications/herald/storage/transcript/HeraldTranscriptResult.php',
|
||||||
'HeraldTranscriptSearchEngine' => 'applications/herald/query/HeraldTranscriptSearchEngine.php',
|
'HeraldTranscriptSearchEngine' => 'applications/herald/query/HeraldTranscriptSearchEngine.php',
|
||||||
'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php',
|
'HeraldTranscriptTestCase' => 'applications/herald/storage/__tests__/HeraldTranscriptTestCase.php',
|
||||||
'HeraldUtilityActionGroup' => 'applications/herald/action/HeraldUtilityActionGroup.php',
|
'HeraldUtilityActionGroup' => 'applications/herald/action/HeraldUtilityActionGroup.php',
|
||||||
|
@ -7794,7 +7795,7 @@ phutil_register_library_map(array(
|
||||||
'HarbormasterBuildableAdapterInterface',
|
'HarbormasterBuildableAdapterInterface',
|
||||||
),
|
),
|
||||||
'HeraldCondition' => 'HeraldDAO',
|
'HeraldCondition' => 'HeraldDAO',
|
||||||
'HeraldConditionResult' => 'Phobject',
|
'HeraldConditionResult' => 'HeraldTranscriptResult',
|
||||||
'HeraldConditionTranscript' => 'Phobject',
|
'HeraldConditionTranscript' => 'Phobject',
|
||||||
'HeraldContentSourceField' => 'HeraldField',
|
'HeraldContentSourceField' => 'HeraldField',
|
||||||
'HeraldController' => 'PhabricatorController',
|
'HeraldController' => 'PhabricatorController',
|
||||||
|
@ -7905,6 +7906,7 @@ phutil_register_library_map(array(
|
||||||
'HeraldTranscriptListController' => 'HeraldController',
|
'HeraldTranscriptListController' => 'HeraldController',
|
||||||
'HeraldTranscriptPHIDType' => 'PhabricatorPHIDType',
|
'HeraldTranscriptPHIDType' => 'PhabricatorPHIDType',
|
||||||
'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'HeraldTranscriptQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
|
'HeraldTranscriptResult' => 'Phobject',
|
||||||
'HeraldTranscriptSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'HeraldTranscriptSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'HeraldTranscriptTestCase' => 'PhabricatorTestCase',
|
'HeraldTranscriptTestCase' => 'PhabricatorTestCase',
|
||||||
'HeraldUtilityActionGroup' => 'HeraldActionGroup',
|
'HeraldUtilityActionGroup' => 'HeraldActionGroup',
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class HeraldConditionResult
|
final class HeraldConditionResult
|
||||||
extends Phobject {
|
extends HeraldTranscriptResult {
|
||||||
|
|
||||||
const RESULT_MATCHED = 'matched';
|
const RESULT_MATCHED = 'matched';
|
||||||
const RESULT_FAILED = 'failed';
|
const RESULT_FAILED = 'failed';
|
||||||
|
@ -10,61 +10,20 @@ final class HeraldConditionResult
|
||||||
const RESULT_EXCEPTION = 'exception';
|
const RESULT_EXCEPTION = 'exception';
|
||||||
const RESULT_UNKNOWN = 'unknown';
|
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) {
|
public static function newFromResultCode($result_code) {
|
||||||
$map = self::getResultSpecification($result_code);
|
return id(new self())->setResultCode($result_code);
|
||||||
|
|
||||||
$result = new self();
|
|
||||||
$result->resultCode = $result_code;
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getResultCode() {
|
public static function newFromResultMap(array $map) {
|
||||||
return $this->resultCode;
|
return id(new self())->loadFromResultMap($map);
|
||||||
}
|
|
||||||
|
|
||||||
private function getResultData() {
|
|
||||||
return $this->resultData;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIconIcon() {
|
|
||||||
return $this->getSpecificationProperty('icon');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getIconColor() {
|
|
||||||
return $this->getSpecificationProperty('color.icon');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIsMatch() {
|
public function getIsMatch() {
|
||||||
return ($this->getSpecificationProperty('match') === true);
|
return ($this->getSpecificationProperty('match') === true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName() {
|
|
||||||
return $this->getSpecificationProperty('name');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function newDetailsView() {
|
public function newDetailsView() {
|
||||||
switch ($this->resultCode) {
|
switch ($this->getResultCode()) {
|
||||||
case self::RESULT_OBJECT_STATE:
|
case self::RESULT_OBJECT_STATE:
|
||||||
$reason = $this->getDataProperty('reason');
|
$reason = $this->getDataProperty('reason');
|
||||||
$details = HeraldStateReasons::getExplanation($reason);
|
$details = HeraldStateReasons::getExplanation($reason);
|
||||||
|
@ -105,35 +64,7 @@ final class HeraldConditionResult
|
||||||
return $details;
|
return $details;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResultData(array $result_data) {
|
protected function newResultSpecificationMap() {
|
||||||
$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() {
|
|
||||||
return array(
|
return array(
|
||||||
self::RESULT_MATCHED => array(
|
self::RESULT_MATCHED => array(
|
||||||
'match' => true,
|
'match' => true,
|
||||||
|
|
|
@ -65,7 +65,7 @@ final class HeraldConditionTranscript extends Phobject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setResult(HeraldConditionResult $result) {
|
public function setResult(HeraldConditionResult $result) {
|
||||||
$this->resultMap = $result->toMap();
|
$this->resultMap = $result->newResultMap();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ final class HeraldConditionTranscript extends Phobject {
|
||||||
$map = $this->resultMap;
|
$map = $this->resultMap;
|
||||||
|
|
||||||
if (is_array($map)) {
|
if (is_array($map)) {
|
||||||
$result = HeraldConditionResult::newFromMap($map);
|
$result = HeraldConditionResult::newFromResultMap($map);
|
||||||
} else {
|
} else {
|
||||||
$legacy_result = $this->result;
|
$legacy_result = $this->result;
|
||||||
|
|
||||||
|
|
|
@ -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();
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue