Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/adapter/HeraldAdapter.php
Show First 20 Lines • Show All 130 Lines • ▼ Show 20 Lines | abstract class HeraldAdapter { | ||||
* NOTE: You generally should not override this; it exists to support legacy | * NOTE: You generally should not override this; it exists to support legacy | ||||
* adapters which had hard-coded content types. | * adapters which had hard-coded content types. | ||||
*/ | */ | ||||
public function getAdapterContentType() { | public function getAdapterContentType() { | ||||
return get_class($this); | return get_class($this); | ||||
} | } | ||||
abstract public function getAdapterContentName(); | abstract public function getAdapterContentName(); | ||||
abstract public function getAdapterContentDescription(); | |||||
abstract public function getAdapterApplicationClass(); | abstract public function getAdapterApplicationClass(); | ||||
abstract public function getObject(); | abstract public function getObject(); | ||||
public function getAdapterSortKey() { | |||||
return sprintf( | |||||
'%08d%s', | |||||
$this->getAdapterSortOrder(), | |||||
$this->getAdapterContentName()); | |||||
} | |||||
public function getAdapterSortOrder() { | |||||
return 1000; | |||||
} | |||||
/* -( Fields )------------------------------------------------------------- */ | /* -( Fields )------------------------------------------------------------- */ | ||||
public function getFields() { | public function getFields() { | ||||
return array( | return array( | ||||
self::FIELD_ALWAYS, | self::FIELD_ALWAYS, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 659 Lines • ▼ Show 20 Lines | /* -( Repetition )--------------------------------------------------------- */ | ||||
} | } | ||||
public static function getAllAdapters() { | public static function getAllAdapters() { | ||||
static $adapters; | static $adapters; | ||||
if (!$adapters) { | if (!$adapters) { | ||||
$adapters = id(new PhutilSymbolLoader()) | $adapters = id(new PhutilSymbolLoader()) | ||||
->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
->loadObjects(); | ->loadObjects(); | ||||
$adapters = msort($adapters, 'getAdapterSortKey'); | |||||
} | } | ||||
return $adapters; | return $adapters; | ||||
} | } | ||||
public static function getAdapterForContentType($content_type) { | public static function getAdapterForContentType($content_type) { | ||||
$adapters = self::getAllAdapters(); | $adapters = self::getAllAdapters(); | ||||
foreach ($adapters as $adapter) { | foreach ($adapters as $adapter) { | ||||
Show All 16 Lines | foreach ($adapters as $adapter) { | ||||
if (!$adapter->isAvailableToUser($viewer)) { | if (!$adapter->isAvailableToUser($viewer)) { | ||||
continue; | continue; | ||||
} | } | ||||
$type = $adapter->getAdapterContentType(); | $type = $adapter->getAdapterContentType(); | ||||
$name = $adapter->getAdapterContentName(); | $name = $adapter->getAdapterContentName(); | ||||
$map[$type] = $name; | $map[$type] = $name; | ||||
} | } | ||||
asort($map); | |||||
return $map; | return $map; | ||||
} | } | ||||
public function renderRuleAsText(HeraldRule $rule, array $handles) { | public function renderRuleAsText(HeraldRule $rule, array $handles) { | ||||
assert_instances_of($handles, 'PhabricatorObjectHandle'); | assert_instances_of($handles, 'PhabricatorObjectHandle'); | ||||
$out = array(); | $out = array(); | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |