Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/conduit/HeraldConduitAPIMethod.php
- This file was added.
<?php | |||||
abstract class HeraldConduitAPIMethod extends ConduitAPIMethod { | |||||
final public function getApplication() { | |||||
return PhabricatorApplication::getByClass( | |||||
'PhabricatorHeraldApplication'); | |||||
} | |||||
public function getMethodStatus() { | |||||
return self::METHOD_STATUS_UNSTABLE; | |||||
} | |||||
public function getMethodStatusDescription() { | |||||
return pht('All Herald APIs are new and subject to change.'); | |||||
} | |||||
protected function buildRuleInfoDictionaries( | |||||
array $plans, $need_conditions_and_actions = false) { | |||||
assert_instances_of($plans, 'HeraldRule'); | |||||
$result = array(); | |||||
foreach ($plans as $plan) { | |||||
$item = array( | |||||
'id' => $plan->getID(), | |||||
'phid' => $plan->getPHID(), | |||||
'name' => $plan->getName(), | |||||
'contentType' => $plan->getContentType(), | |||||
'mustMatchAll' => $plan->getMustMatchAll(), | |||||
'ruleType' => $plan->getRuleType(), | |||||
'dateCreated' => $plan->getDateCreated(), | |||||
'dateModified' => $plan->getDateModified(), | |||||
); | |||||
if ($need_conditions_and_actions) { | |||||
$conditions = is_array($plan->getConditions()) | |||||
? $plan->getConditions() : array(); | |||||
$actions = is_array($plan->getActions()) | |||||
? $plan->getActions() : array(); | |||||
$item['conditions'] = | |||||
$this->buildConditionsInfoDictionaries($conditions); | |||||
$item['actions'] = | |||||
$this->buildActionsInfoDictionaries($actions); | |||||
} | |||||
$result[$plan->getPHID()] = $item; | |||||
} | |||||
return $result; | |||||
} | |||||
protected function buildConditionsInfoDictionaries(array $conditions) { | |||||
assert_instances_of($conditions, 'HeraldCondition'); | |||||
$result = array(); | |||||
if (!empty($conditions)) { | |||||
foreach ($conditions as $cond) { | |||||
$result[$cond->getID()] = array( | |||||
'id' => $cond->getID(), | |||||
'fieldName' => $cond->getFieldName(), | |||||
'fieldCondition' => $cond->getFieldCondition(), | |||||
'value' => $cond->getValue(), | |||||
); | |||||
} | |||||
} | |||||
return $result; | |||||
} | |||||
protected function buildActionsInfoDictionaries(array $actions) { | |||||
assert_instances_of($actions, 'HeraldAction'); | |||||
$result = array(); | |||||
if (!empty($actions)) { | |||||
foreach ($actions as $action) { | |||||
$result[$action->getID()] = array( | |||||
'id' => $action->getID(), | |||||
'action' => $action->getAction(), | |||||
'target' => $action->getTarget(), | |||||
); | |||||
} | |||||
} | |||||
return $result; | |||||
} | |||||
} |