Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / herald / editor / HeraldRuleSerializer.php
blobcf045fc9bf49118fa16c98f28648ab8a90d2b2e8
1 <?php
3 /**
4 * Serialize for RuleTransactions / Editor.
5 */
6 final class HeraldRuleSerializer extends Phobject {
7 public function serializeRule(HeraldRule $rule) {
8 return $this->serializeRuleComponents(
9 (bool)$rule->getMustMatchAll(),
10 $rule->getConditions(),
11 $rule->getActions(),
12 $rule->getRepetitionPolicyStringConstant());
15 public function serializeRuleComponents(
16 $match_all,
17 array $conditions,
18 array $actions,
19 $repetition_policy) {
21 assert_instances_of($conditions, 'HeraldCondition');
22 assert_instances_of($actions, 'HeraldActionRecord');
24 $conditions_array = array();
25 foreach ($conditions as $condition) {
26 $conditions_array[] = array(
27 'field' => $condition->getFieldName(),
28 'condition' => $condition->getFieldCondition(),
29 'value' => $condition->getValue(),
33 $actions_array = array();
34 foreach ($actions as $action) {
35 $actions_array[] = array(
36 'action' => $action->getAction(),
37 'target' => $action->getTarget(),
41 return array(
42 'match_all' => $match_all,
43 'conditions' => $conditions_array,
44 'actions' => $actions_array,
45 'repetition_policy' => $repetition_policy,
49 public function deserializeRuleComponents(array $serialized) {
50 $deser_conditions = array();
51 foreach ($serialized['conditions'] as $condition) {
52 $deser_conditions[] = id(new HeraldCondition())
53 ->setFieldName($condition['field'])
54 ->setFieldCondition($condition['condition'])
55 ->setValue($condition['value']);
58 $deser_actions = array();
59 foreach ($serialized['actions'] as $action) {
60 $deser_actions[] = id(new HeraldActionRecord())
61 ->setAction($action['action'])
62 ->setTarget($action['target']);
65 return array(
66 'match_all' => $serialized['match_all'],
67 'conditions' => $deser_conditions,
68 'actions' => $deser_actions,
69 'repetition_policy' => $serialized['repetition_policy'],