Skip to content

Commit

Permalink
cleaning up core_component api a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
snake committed Jun 26, 2024
1 parent 0b64ac9 commit 8715688
Show file tree
Hide file tree
Showing 12 changed files with 394 additions and 242 deletions.
109 changes: 70 additions & 39 deletions lib/classes/component.php
Original file line number Diff line number Diff line change
Expand Up @@ -933,22 +933,24 @@ public static function get_core_apis() {
/**
* Get list of available plugin types together with their location.
*
* @param bool $includedeprecated whether to include deprecated plugin types.
* @return array as (string)plugintype => (string)fulldir
*/
public static function get_plugin_types() {
public static function get_plugin_types(bool $includedeprecated = false) {
self::init();
return self::$plugintypes;

return $includedeprecated ? array_merge(self::$plugintypes, self::$deprecatedplugintypes) : self::$plugintypes;
}

/**
* Get a list of deprecated plugin types adn their locations.
*
* @return array as (string)plugintype => (string)fulldir
*/
public static function get_deprecated_plugin_types(): array {
self::init();
return self::$deprecatedplugintypes;
}
// public static function get_deprecated_plugin_types(): array {
// self::init();
// return self::$deprecatedplugintypes;
// }

/**
* Is the plugintype deprecated.
Expand All @@ -961,15 +963,35 @@ public static function is_deprecated_plugin_type(string $plugintype): bool {
return array_key_exists($plugintype, self::$deprecatedplugintypes);
}

/**
* Is the plugin of a deprecated type.
*
* @param string $pluginname
* @return bool true if deprecated, false otherwise.
*/
public static function is_deprecated_plugin(string $pluginname): bool {
self::init();
[$type, $name] = self::normalize_component($pluginname);
return array_key_exists($name, self::$deprecatedplugins[$type] ?? []);
}

/**
* Get list of plugins of given type.
*
* @param string $plugintype
* @param bool $includedeprecated whether to include deprecated plugins.
* @return array as (string)pluginname => (string)fulldir
*/
public static function get_plugin_list($plugintype) {
public static function get_plugin_list($plugintype, bool $includedeprecated = false) {
self::init();

if ($includedeprecated) {
if (!isset(self::$plugins[$plugintype]) && !isset(self::$deprecatedplugins[$plugintype])) {
return [];
}
return array_merge(self::$plugins[$plugintype] ?? [], self::$deprecatedplugins[$plugintype] ?? []);
}

if (!isset(self::$plugins[$plugintype])) {
return [];
}
Expand All @@ -982,14 +1004,14 @@ public static function get_plugin_list($plugintype) {
* @param string $plugintype
* @return array as (string)pluginname => (string)fulldir
*/
public static function get_deprecated_plugin_list($plugintype): array {
self::init();

if (!isset(self::$deprecatedplugins[$plugintype])) {
return [];
}
return self::$deprecatedplugins[$plugintype];
}
// public static function get_deprecated_plugin_list($plugintype): array {
// self::init();
//
// if (!isset(self::$deprecatedplugins[$plugintype])) {
// return [];
// }
// return self::$deprecatedplugins[$plugintype];
// }

/**
* Get a list of all the plugins of a given type that define a certain class
Expand Down Expand Up @@ -1322,11 +1344,19 @@ public static function get_subtype_parent($type) {
/**
* Return all subplugins of this component.
* @param string $component.
* @param bool $includedeprecated whether to include deprecated plugins.
* @return array $subtype=>array($component, ..), null if no subtypes defined
*/
public static function get_subplugins($component) {
public static function get_subplugins($component) {//}, bool $includedeprecated = false) {
self::init();

// if ($includedeprecated) {
// if (!isset(self::$subplugins[$component]) && !isset(self::$deprecatedsubplugins[$component])) {
// return null;
// }
// return array_merge(self::$subplugins[$component] ?? [], self::$deprecatedsubplugins[$component] ?? []);
// }

if (isset(self::$subplugins[$component])) {
return self::$subplugins[$component];
}
Expand All @@ -1339,15 +1369,15 @@ public static function get_subplugins($component) {
* @param string $component.
* @return array $subtype=>array($component, ..), null if no subtypes defined
*/
public static function get_deprecated_subplugins($component) {
self::init();

if (isset(self::$deprecatedsubplugins[$component])) {
return self::$deprecatedsubplugins[$component];
}

return null;
}
// public static function get_deprecated_subplugins($component) {
// self::init();
//
// if (isset(self::$deprecatedsubplugins[$component])) {
// return self::$deprecatedsubplugins[$component];
// }
//
// return null;
// }

/**
* Returns hash of all versions including core and all plugins.
Expand Down Expand Up @@ -1581,14 +1611,15 @@ protected static function load_renamed_classes(?string $fulldir) {
* ]
* ]
*
* @param bool $includedeprecatedplugins whether to include deprecated plugins.
* @return array an associative array of components and their corresponding paths.
*/
public static function get_component_list(): array {
public static function get_component_list(bool $includedeprecatedplugins = false): array {
$components = [];
// Get all plugins.
foreach (self::get_plugin_types() as $plugintype => $typedir) {
foreach (self::get_plugin_types($includedeprecatedplugins) as $plugintype => $typedir) {
$components[$plugintype] = [];
foreach (self::get_plugin_list($plugintype) as $pluginname => $plugindir) {
foreach (self::get_plugin_list($plugintype, $includedeprecatedplugins) as $pluginname => $plugindir) {
$components[$plugintype][$plugintype . '_' . $pluginname] = $plugindir;
}
}
Expand All @@ -1605,17 +1636,17 @@ public static function get_component_list(): array {
* Note: By default the 'core' subsystem is not included.
*
* @param bool $includecore Whether to include the 'core' subsystem
* @param bool $includedeprecated Whether to include the deprecated plugins
* @param bool $includedeprecatedplugins Whether to include the deprecated plugins.
* @return string[] the list of frankenstyle component names.
*/
public static function get_component_names(
bool $includecore = false,
bool $includedeprecated = false
bool $includedeprecatedplugins = false
): array {
$componentnames = [];
// Get all plugins.
foreach (self::get_plugin_types() as $plugintype => $typedir) {
foreach (self::get_plugin_list($plugintype) as $pluginname => $plugindir) {
foreach (self::get_plugin_types($includedeprecatedplugins) as $plugintype => $typedir) {
foreach (self::get_plugin_list($plugintype, $includedeprecatedplugins) as $pluginname => $plugindir) {
$componentnames[] = $plugintype . '_' . $pluginname;
}
}
Expand All @@ -1628,13 +1659,13 @@ public static function get_component_names(
$componentnames[] = 'core';
}

if ($includedeprecated) {
foreach (self::get_deprecated_plugin_types() as $plugintype => $typedir) {
foreach (self::get_deprecated_plugin_list($plugintype) as $pluginname => $plugindir) {
$componentnames[] = $plugintype . '_' . $pluginname;
}
}
}
// if ($includedeprecated) {
// foreach (self::get_deprecated_plugin_types() as $plugintype => $typedir) {
// foreach (self::get_deprecated_plugin_list($plugintype) as $pluginname => $plugindir) {
// $componentnames[] = $plugintype . '_' . $pluginname;
// }
// }
// }

return $componentnames;
}
Expand Down
Loading

0 comments on commit 8715688

Please sign in to comment.