Skip to content

Commit

Permalink
Add fetchLocalPlugins method to Pluggable
Browse files Browse the repository at this point in the history
  • Loading branch information
donhardman committed Feb 19, 2024
1 parent 4860b28 commit 715e60e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Plugin/Pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,47 @@ public function fetchCorePlugins(): array {
return $plugins;
}

/**
* Helper to fetch local plugins
* @return array<array{full:string,short:string,version:string}>
* @throws Exception
*/
public function fetchLocalPlugins(): array {
$localPluginDir = realpath(__DIR__ . '/../../../../../plugins');
if (false === $localPluginDir) {
throw new Exception('Failed to detect local plugin dir');
}
$plugins = [];
$items = scandir($localPluginDir);
if (false === $items) {
throw new Exception('Failed to readh local plugin dir');
}
foreach ($items as $item) {
if (!is_dir("$localPluginDir/$item") || $item === '.' || $item === '..') {
continue;
}

$shortName = str_replace(static::PLUGIN_PREFIX, '', $item);
$composerFile = "$localPluginDir/$item/composer.json";
$composerContent = file_get_contents($composerFile);
if (!is_string($composerContent)) {
throw new Exception("Failed to read composer file for plugin: $shortName");
}
/** @var array{name:?string} */
$composer = json_decode($composerContent, true);
if (!isset($composer['name'])) {
throw new Exception("Failed to detect local plugin name from file: $composerFile");
}
$plugins[] = [
'full' => $composer['name'],
'short' => $shortName,
'version' => 'dev-main',
];
}

return $plugins;
}

/**
* Get list of external plugin names
* @return array<array{full:string,short:string,version:string}>
Expand Down

0 comments on commit 715e60e

Please sign in to comment.