Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/autoplan/HarbormasterBuildAutoplan.php
<?php | <?php | ||||
abstract class HarbormasterBuildAutoplan extends Phobject { | abstract class HarbormasterBuildAutoplan extends Phobject { | ||||
abstract public function getAutoplanPlanKey(); | abstract public function getAutoplanPlanKey(); | ||||
abstract public function getAutoplanName(); | abstract public function getAutoplanName(); | ||||
public static function getAutoplan($key) { | public static function getAutoplan($key) { | ||||
return idx(self::getAllAutoplans(), $key); | return idx(self::getAllAutoplans(), $key); | ||||
} | } | ||||
public static function getAllAutoplans() { | public static function getAllAutoplans() { | ||||
static $plans; | return id(new PhutilClassMapQuery()) | ||||
if ($plans === null) { | |||||
$objects = id(new PhutilSymbolLoader()) | |||||
->setAncestorClass(__CLASS__) | ->setAncestorClass(__CLASS__) | ||||
->loadObjects(); | ->setUniqueMethod('getAutoplanPlanKey') | ||||
->execute(); | |||||
$map = array(); | |||||
foreach ($objects as $object) { | |||||
$key = $object->getAutoplanPlanKey(); | |||||
if (!empty($map[$key])) { | |||||
$other = $map[$key]; | |||||
throw new Exception( | |||||
pht( | |||||
'Two build autoplans (of classes "%s" and "%s") define the same '. | |||||
'key ("%s"). Each autoplan must have a unique key.', | |||||
get_class($other), | |||||
get_class($object), | |||||
$key)); | |||||
} | |||||
$map[$key] = $object; | |||||
} | |||||
ksort($map); | |||||
$plans = $map; | |||||
} | |||||
return $plans; | |||||
} | } | ||||
} | } |