Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/action/HeraldAction.php
<?php | <?php | ||||
abstract class HeraldAction extends Phobject { | abstract class HeraldAction extends Phobject { | ||||
private $adapter; | private $adapter; | ||||
private $viewer; | |||||
private $applyLog = array(); | private $applyLog = array(); | ||||
const STANDARD_NONE = 'standard.none'; | const STANDARD_NONE = 'standard.none'; | ||||
const STANDARD_PHID_LIST = 'standard.phid.list'; | const STANDARD_PHID_LIST = 'standard.phid.list'; | ||||
abstract public function getHeraldActionName(); | abstract public function getHeraldActionName(); | ||||
abstract public function supportsObject($object); | abstract public function supportsObject($object); | ||||
abstract public function supportsRuleType($rule_type); | abstract public function supportsRuleType($rule_type); | ||||
abstract public function applyEffect($object, HeraldEffect $effect); | abstract public function applyEffect($object, HeraldEffect $effect); | ||||
abstract public function renderActionEffectDescription($type, $data); | |||||
public function getActionGroupKey() { | public function getActionGroupKey() { | ||||
return null; | return null; | ||||
} | } | ||||
public function getActionsForObject($object) { | public function getActionsForObject($object) { | ||||
return array($this->getActionConstant() => $this); | return array($this->getActionConstant() => $this); | ||||
} | } | ||||
Show All 38 Lines | final public function setAdapter(HeraldAdapter $adapter) { | ||||
$this->adapter = $adapter; | $this->adapter = $adapter; | ||||
return $this; | return $this; | ||||
} | } | ||||
final public function getAdapter() { | final public function getAdapter() { | ||||
return $this->adapter; | return $this->adapter; | ||||
} | } | ||||
final public function setViewer(PhabricatorUser $viewer) { | |||||
$this->viewer = $viewer; | |||||
return $this; | |||||
} | |||||
final public function getViewer() { | |||||
return $this->viewer; | |||||
} | |||||
final public function getActionConstant() { | final public function getActionConstant() { | ||||
$class = new ReflectionClass($this); | $class = new ReflectionClass($this); | ||||
$const = $class->getConstant('ACTIONCONST'); | $const = $class->getConstant('ACTIONCONST'); | ||||
if ($const === false) { | if ($const === false) { | ||||
throw new Exception( | throw new Exception( | ||||
pht( | pht( | ||||
'"%s" class "%s" must define a "%s" property.', | '"%s" class "%s" must define a "%s" property.', | ||||
Show All 24 Lines | abstract class HeraldAction extends Phobject { | ||||
final public static function getAllActions() { | final public static function getAllActions() { | ||||
return id(new PhutilClassMapQuery()) | return id(new PhutilClassMapQuery()) | ||||
->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
->setUniqueMethod('getActionConstant') | ->setUniqueMethod('getActionConstant') | ||||
->execute(); | ->execute(); | ||||
} | } | ||||
protected function logEffect($type, $data = null) { | protected function logEffect($type, $data = null) { | ||||
return; | if (!is_string($type)) { | ||||
throw new Exception( | |||||
pht( | |||||
'Effect type passed to "%s" must be a scalar string.', | |||||
'logEffect()')); | |||||
} | |||||
$this->applyLog[] = array( | |||||
'type' => $type, | |||||
'data' => $data, | |||||
); | |||||
return $this; | |||||
} | } | ||||
final public function getApplyTranscript(HeraldEffect $effect) { | final public function getApplyTranscript(HeraldEffect $effect) { | ||||
$context = 'v2/'.phutil_json_encode($this->applyLog); | $context = $this->applyLog; | ||||
$this->applyLog = array(); | $this->applyLog = array(); | ||||
return new HeraldApplyTranscript($effect, true, $context); | return new HeraldApplyTranscript($effect, true, $context); | ||||
} | } | ||||
protected function getActionEffectMap() { | |||||
throw new PhutilMethodNotImplementedException(); | |||||
} | |||||
private function getActionEffectSpec($type) { | |||||
$map = $this->getActionEffectMap(); | |||||
return idx($map, $type, array()); | |||||
} | |||||
public function renderActionEffectIcon($type, $data) { | |||||
$map = $this->getActionEffectSpec($type); | |||||
return idx($map, 'icon'); | |||||
} | |||||
public function renderActionEffectColor($type, $data) { | |||||
$map = $this->getActionEffectSpec($type); | |||||
return idx($map, 'color'); | |||||
} | |||||
public function renderActionEffectName($type, $data) { | |||||
$map = $this->getActionEffectSpec($type); | |||||
return idx($map, 'name'); | |||||
} | |||||
} | } |