[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 abstract class HeraldPreCommitAdapter extends HeraldAdapter { 4 5 private $log; 6 private $hookEngine; 7 private $emailPHIDs = array(); 8 9 public function setPushLog(PhabricatorRepositoryPushLog $log) { 10 $this->log = $log; 11 return $this; 12 } 13 14 public function setHookEngine(DiffusionCommitHookEngine $engine) { 15 $this->hookEngine = $engine; 16 return $this; 17 } 18 19 public function getHookEngine() { 20 return $this->hookEngine; 21 } 22 23 public function getAdapterApplicationClass() { 24 return 'PhabricatorDiffusionApplication'; 25 } 26 27 public function getObject() { 28 return $this->log; 29 } 30 31 public function getEmailPHIDs() { 32 return array_values($this->emailPHIDs); 33 } 34 35 public function supportsRuleType($rule_type) { 36 switch ($rule_type) { 37 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 38 case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 39 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 40 return true; 41 default: 42 return false; 43 } 44 } 45 46 public function canTriggerOnObject($object) { 47 if ($object instanceof PhabricatorRepository) { 48 return true; 49 } 50 51 if ($object instanceof PhabricatorProject) { 52 return true; 53 } 54 55 return false; 56 } 57 58 public function explainValidTriggerObjects() { 59 return pht('This rule can trigger for **repositories** or **projects**.'); 60 } 61 62 public function getTriggerObjectPHIDs() { 63 return array_merge( 64 array( 65 $this->hookEngine->getRepository()->getPHID(), 66 $this->getPHID(), 67 ), 68 $this->hookEngine->getRepository()->getProjectPHIDs()); 69 } 70 71 public function getActions($rule_type) { 72 switch ($rule_type) { 73 case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 74 case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 75 return array_merge( 76 array( 77 self::ACTION_BLOCK, 78 self::ACTION_EMAIL, 79 self::ACTION_NOTHING, 80 ), 81 parent::getActions($rule_type)); 82 case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 83 return array_merge( 84 array( 85 self::ACTION_EMAIL, 86 self::ACTION_NOTHING, 87 ), 88 parent::getActions($rule_type)); 89 } 90 } 91 92 public function getPHID() { 93 return $this->getObject()->getPHID(); 94 } 95 96 public function applyHeraldEffects(array $effects) { 97 assert_instances_of($effects, 'HeraldEffect'); 98 99 $result = array(); 100 foreach ($effects as $effect) { 101 $action = $effect->getAction(); 102 switch ($action) { 103 case self::ACTION_NOTHING: 104 $result[] = new HeraldApplyTranscript( 105 $effect, 106 true, 107 pht('Did nothing.')); 108 break; 109 case self::ACTION_EMAIL: 110 foreach ($effect->getTarget() as $phid) { 111 $this->emailPHIDs[$phid] = $phid; 112 } 113 $result[] = new HeraldApplyTranscript( 114 $effect, 115 true, 116 pht('Added mailable to mail targets.')); 117 break; 118 case self::ACTION_BLOCK: 119 $result[] = new HeraldApplyTranscript( 120 $effect, 121 true, 122 pht('Blocked push.')); 123 break; 124 default: 125 $custom_result = parent::handleCustomHeraldEffect($effect); 126 if ($custom_result === null) { 127 throw new Exception(pht( 128 "No rules to handle action '%s'.", 129 $action)); 130 } 131 132 $result[] = $custom_result; 133 break; 134 } 135 } 136 137 return $result; 138 } 139 140 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |