1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-23 05:50:55 +01:00

Use PhutilClassMapQuery

Summary: Use `PhutilClassMapQuery` where appropriate.

Test Plan: Browsed around the UI to verify things seemed somewhat working.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Differential Revision: https://secure.phabricator.com/D13429
This commit is contained in:
Joshua Spence 2015-07-07 22:34:30 +10:00
parent 6a3c1ba05c
commit f695dcea9e
27 changed files with 102 additions and 443 deletions

View file

@ -65,11 +65,11 @@ abstract class AlmanacServiceType extends Phobject {
* @return map<string, object> Dictionary of available service types.
*/
public static function getAllServiceTypes() {
$types = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
return msort($types, 'getServiceTypeName');
->setUniqueMethod('getServiceTypeShortName')
->setSortMethod('getServiceTypeName')
->execute();
}

View file

@ -34,35 +34,10 @@ abstract class PhabricatorAuthFactor extends Phobject {
}
public static function getAllFactors() {
static $factors;
if ($factors === null) {
$map = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$factors = array();
foreach ($map as $factor) {
$key = $factor->getFactorKey();
if (empty($factors[$key])) {
$factors[$key] = $factor;
} else {
$this_class = get_class($factor);
$that_class = get_class($factors[$key]);
throw new Exception(
pht(
'Two auth factors (with classes "%s" and "%s") both provide '.
'implementations with the same key ("%s"). Each factor must '.
'have a unique key.',
$this_class,
$that_class,
$key));
}
}
}
return $factors;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getFactorKey')
->execute();
}
protected function newConfigForUser(PhabricatorUser $user) {

View file

@ -55,16 +55,9 @@ abstract class PhabricatorAuthProvider extends Phobject {
}
public static function getAllBaseProviders() {
static $providers;
if ($providers === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$providers = $objects;
}
return $providers;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
}
public static function getAllProviders() {

View file

@ -383,13 +383,13 @@ abstract class PhabricatorApplication
static $applications;
if ($applications === null) {
$apps = id(new PhutilSymbolLoader())
$apps = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
->setSortMethod('getApplicationOrder')
->execute();
// Reorder the applications into "application order". Notably, this
// ensures their event handlers register in application order.
$apps = msort($apps, 'getApplicationOrder');
$apps = mgroup($apps, 'getApplicationGroup');
$group_order = array_keys(self::getApplicationGroups());

View file

@ -36,34 +36,10 @@ abstract class CelerityPostprocessor
}
final public static function getAllPostprocessors() {
static $postprocessors;
if ($postprocessors === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
foreach ($objects as $object) {
$key = $object->getPostprocessorKey();
if (empty($map[$key])) {
$map[$key] = $object;
continue;
}
throw new Exception(
pht(
'Two postprocessors (of classes "%s" and "%s") define the same '.
'postprocessor key ("%s"). Each postprocessor must define a '.
'unique key.',
get_class($object),
get_class($map[$key]),
$key));
}
$postprocessors = $map;
}
return $postprocessors;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getPostprocessorKey')
->execute();
}
}

View file

@ -23,11 +23,10 @@ abstract class CelerityPhysicalResources extends CelerityResources {
static $resources_map;
if ($resources_map === null) {
$resources_map = array();
$resources_list = id(new PhutilSymbolLoader())
$resources_list = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
->setUniqueMethod('getName')
->execute();
foreach ($resources_list as $resources) {
$name = $resources->getName();
@ -39,21 +38,9 @@ abstract class CelerityPhysicalResources extends CelerityResources {
'lowercase latin letters and digits.',
$name));
}
if (empty($resources_map[$name])) {
$resources_map[$name] = $resources;
} else {
$old = get_class($resources_map[$name]);
$new = get_class($resources);
throw new Exception(
pht(
'Celerity resource maps must have unique names, but maps %s and '.
'%s share the same name, "%s".',
$old,
$new,
$name));
}
}
$resources_map = $resources_list;
}
return $resources_map;

View file

@ -112,17 +112,10 @@ abstract class PhabricatorSetupCheck extends Phobject {
}
final public static function loadAllChecks() {
$symbols = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setConcreteOnly(true)
->selectAndLoadSymbols();
$checks = array();
foreach ($symbols as $symbol) {
$checks[] = newv($symbol['name'], array());
}
return msort($checks, 'getExecutionOrder');
->setSortMethod('getExecutionOrder')
->execute();
}
final public static function runAllChecks() {

View file

@ -46,36 +46,10 @@ abstract class PhabricatorDashboardPanelType extends Phobject {
}
public static function getAllPanelTypes() {
static $types;
if ($types === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
foreach ($objects as $object) {
$key = $object->getPanelTypeKey();
if (!empty($map[$key])) {
$this_class = get_class($object);
$that_class = get_class($map[$key]);
throw new Exception(
pht(
'Two dashboard panels (of classes "%s" and "%s") have the '.
'same panel type key ("%s"). Each panel type must have a '.
'unique panel type key.',
$this_class,
$that_class,
$key));
}
$map[$key] = $object;
}
$types = $map;
}
return $types;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getPanelTypeKey')
->execute();
}
}

View file

@ -372,21 +372,9 @@ abstract class DrydockBlueprintImplementation extends Phobject {
public static function getAllBlueprintImplementations() {
static $list = null;
if ($list === null) {
$blueprints = id(new PhutilSymbolLoader())
->setType('class')
->setAncestorClass(__CLASS__)
->setConcreteOnly(true)
->selectAndLoadSymbols();
$list = ipull($blueprints, 'name', 'name');
foreach ($list as $class_name => $ignored) {
$list[$class_name] = newv($class_name, array());
}
}
return $list;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->execute();
}
public static function getAllBlueprintImplementationsForResource($type) {

View file

@ -3,17 +3,9 @@
abstract class PhabricatorFactEngine extends Phobject {
final public static function loadAllEngines() {
$classes = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setConcreteOnly(true)
->selectAndLoadSymbols();
$objects = array();
foreach ($classes as $class) {
$objects[] = newv($class['name'], array());
}
return $objects;
->execute();
}
public function getFactSpecs(array $fact_types) {

View file

@ -224,36 +224,11 @@ abstract class PhabricatorFileStorageEngine extends Phobject {
* @task load
*/
public static function loadAllEngines() {
static $engines;
if ($engines === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
foreach ($objects as $engine) {
$key = $engine->getEngineIdentifier();
if (empty($map[$key])) {
$map[$key] = $engine;
} else {
throw new Exception(
pht(
'Storage engines "%s" and "%s" have the same engine '.
'identifier "%s". Each storage engine must have a unique '.
'identifier.',
get_class($engine),
get_class($map[$key]),
$key));
}
}
$map = msort($map, 'getEnginePriority');
$engines = $map;
}
return $engines;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getEngineIdentifier')
->setSortMethod('getEnginePriority')
->execute();
}

View file

@ -28,33 +28,11 @@ abstract class PhabricatorFileTransform extends Phobject {
}
public static function getAllTransforms() {
static $map;
if ($map === null) {
$xforms = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$result = array();
foreach ($xforms as $xform_template) {
foreach ($xform_template->generateTransforms() as $xform) {
$key = $xform->getTransformKey();
if (isset($result[$key])) {
throw new Exception(
pht(
'Two %s objects define the same transform key ("%s"), but '.
'each transform must have a unique key.',
__CLASS__,
$key));
}
$result[$key] = $xform;
}
}
$map = $result;
}
return $map;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setExpandMethod('generateTransforms')
->setUniqueMethod('getTransformKey')
->execute();
}
public static function getTransformByKey($key) {

View file

@ -10,35 +10,10 @@ abstract class HarbormasterBuildAutoplan extends Phobject {
}
public static function getAllAutoplans() {
static $plans;
if ($plans === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$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;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getAutoplanPlanKey')
->execute();
}
}

View file

@ -8,9 +8,9 @@ abstract class HarbormasterBuildStepImplementation extends Phobject {
private $settings;
public static function getImplementations() {
return id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
->execute();
}
public static function getImplementation($class) {

View file

@ -1023,14 +1023,11 @@ abstract class HeraldAdapter extends Phobject {
}
public static function getAllAdapters() {
static $adapters;
if (!$adapters) {
$adapters = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$adapters = msort($adapters, 'getAdapterSortKey');
}
return $adapters;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getAdapterContentType')
->setSortMethod('getAdapterSortKey')
->execute();
}
public static function getAdapterForContentType($content_type) {

View file

@ -3,19 +3,10 @@
abstract class ManiphestExcelFormat extends Phobject {
final public static function loadAllFormats() {
$classes = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setConcreteOnly(true)
->selectAndLoadSymbols();
$objects = array();
foreach ($classes as $class) {
$objects[$class['name']] = newv($class['name'], array());
}
$objects = msort($objects, 'getOrder');
return $objects;
->setSortMethod('getOrder')
->execute();
}
abstract public function getName();

View file

@ -47,27 +47,10 @@ abstract class PhabricatorApplicationConfigurationPanel
PhabricatorController $controller);
public static function loadAllPanels() {
$objects = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
$panels = array();
foreach ($objects as $object) {
$key = $object->getPanelKey();
if (empty($panels[$key])) {
$panels[$key] = $object;
} else {
throw new Exception(
pht(
'Application configuration panels "%s" and "%s" have the same '.
'panel key, "%s". Each panel must have a unique key.',
get_class($object),
get_class($panels[$key]),
$key));
}
}
return $panels;
->setUniqueMethod('getPanelKey')
->execute();
}
public static function loadAllPanelsForApplication(

View file

@ -60,21 +60,11 @@ abstract class MetaMTAEmailTransactionCommand extends Phobject {
}
public static function getAllCommands() {
static $commands;
if ($commands === null) {
$kinds = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$commands = array();
foreach ($kinds as $kind) {
foreach ($kind->getCommandObjects() as $command) {
$commands[] = $command;
}
}
}
return $commands;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setExpandMethod('getCommandObjects')
->setUniqueMethod('getCommand')
->execute();
}
public static function getAllCommandsForObject(

View file

@ -58,31 +58,10 @@ abstract class NuanceSourceDefinition extends Phobject {
}
public static function getAllDefinitions() {
static $definitions;
if ($definitions === null) {
$definitions = array();
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
foreach ($objects as $definition) {
$key = $definition->getSourceTypeConstant();
$name = $definition->getName();
if (isset($definitions[$key])) {
$conflict = $definitions[$key];
throw new Exception(
pht(
'Definition %s conflicts with definition %s. This is a '.
'programming error.',
$conflict,
$name));
}
$definitions[$key] = $definition;
}
}
return $definitions;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getSourceTypeConstant')
->execute();
}
/**

View file

@ -16,10 +16,10 @@ abstract class PassphraseCredentialType extends Phobject {
}
public static function getAllTypes() {
$types = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
return $types;
->setUniqueMethod('getCredentialType')
->execute();
}
public static function getAllCreateableTypes() {

View file

@ -159,37 +159,10 @@ abstract class PhabricatorPHIDType extends Phobject {
* @return dict<string, PhabricatorPHIDType> Map of type constants to types.
*/
final public static function getAllTypes() {
static $types;
if ($types === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
$original = array();
foreach ($objects as $object) {
$type = $object->getTypeConstant();
if (isset($map[$type])) {
$that_class = $original[$type];
$this_class = get_class($object);
throw new Exception(
pht(
"Two %s classes (%s, %s) both handle PHID type '%s'. ".
"A type may be handled by only one class.",
__CLASS__,
$that_class,
$this_class,
$type));
}
$original[$type] = get_class($object);
$map[$type] = $object;
}
$types = $map;
}
return $types;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getTypeConstant')
->execute();
}

View file

@ -117,9 +117,9 @@ abstract class PhortunePaymentProvider extends Phobject {
public static function getAllProviders() {
return id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
->execute();
}
public function isEnabled() {

View file

@ -79,16 +79,10 @@ abstract class PhabricatorPolicyCapability extends Phobject {
}
final public static function getCapabilityMap() {
static $map;
if ($map === null) {
$capabilities = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = mpull($capabilities, null, 'getCapabilityKey');
}
return $map;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getCapabilityKey')
->execute();
}
}

View file

@ -559,11 +559,9 @@ abstract class PhabricatorApplicationSearchEngine extends Phobject {
* @task construct
*/
public static function getAllEngines() {
$engines = id(new PhutilSymbolLoader())
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
return $engines;
->execute();
}

View file

@ -106,35 +106,11 @@ abstract class PhabricatorSearchEngine extends Phobject {
* @task load
*/
public static function loadAllEngines() {
static $engines;
if ($engines === null) {
$objects = id(new PhutilSymbolLoader())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
foreach ($objects as $engine) {
$key = $engine->getEngineIdentifier();
if (empty($map[$key])) {
$map[$key] = $engine;
} else {
throw new Exception(
pht(
'Search engines "%s" and "%s" have the same engine identifier '.
'"%s". Each storage engine must have a unique identifier.',
get_class($engine),
get_class($map[$key]),
$key));
}
}
$map = msort($map, 'getEnginePriority');
$engines = $map;
}
return $engines;
return id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->setUniqueMethod('getEngineIdentifier')
->setSortMethod('getEnginePriority')
->execute();
}
/**

View file

@ -156,39 +156,22 @@ abstract class PhabricatorEdgeType extends Phobject {
static $type_map;
if ($type_map === null) {
$types = id(new PhutilSymbolLoader())
$types = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
$map = array();
foreach ($types as $class => $type) {
$const = $type->getEdgeConstant();
if (isset($map[$const])) {
throw new Exception(
pht(
'Two edge types ("%s", "%s") share the same edge constant '.
'(%d). Each edge type must have a unique constant.',
$class,
get_class($map[$const]),
$const));
}
$map[$const] = $type;
}
->setUniqueMethod('getEdgeConstant')
->execute();
// Check that all the inverse edge definitions actually make sense. If
// edge type A says B is its inverse, B must exist and say that A is its
// inverse.
foreach ($map as $const => $type) {
foreach ($types as $const => $type) {
$inverse = $type->getInverseEdgeConstant();
if ($inverse === null) {
continue;
}
if (empty($map[$inverse])) {
if (empty($types[$inverse])) {
throw new Exception(
pht(
'Edge type "%s" ("%d") defines an inverse type ("%d") which '.
@ -198,7 +181,7 @@ abstract class PhabricatorEdgeType extends Phobject {
$inverse));
}
$inverse_inverse = $map[$inverse]->getInverseEdgeConstant();
$inverse_inverse = $types[$inverse]->getInverseEdgeConstant();
if ($inverse_inverse !== $const) {
throw new Exception(
pht(
@ -212,7 +195,7 @@ abstract class PhabricatorEdgeType extends Phobject {
}
}
$type_map = $map;
$type_map = $types;
}
return $type_map;

View file

@ -212,11 +212,11 @@ abstract class PhabricatorPasswordHasher extends Phobject {
* @task hashing
*/
public static function getAllHashers() {
$objects = id(new PhutilSymbolLoader())
$objects = id(new PhutilClassMapQuery())
->setAncestorClass(__CLASS__)
->loadObjects();
->setUniqueMethod('getHashName')
->execute();
$map = array();
foreach ($objects as $object) {
$name = $object->getHashName();
@ -233,20 +233,9 @@ abstract class PhabricatorPasswordHasher extends Phobject {
$maximum_length,
$potential_length));
}
if (isset($map[$name])) {
throw new Exception(
pht(
'Two hashers use the same hash name ("%s"), "%s" and "%s". Each '.
'hasher must have a unique name.',
$name,
get_class($object),
get_class($map[$name])));
}
$map[$name] = $object;
}
return $map;
return $objects;
}