Move getPluginManifest() to PluginInstaller class

This commit is contained in:
billz
2024-12-21 10:40:41 -08:00
parent ee38614334
commit 6785cc1104
2 changed files with 37 additions and 33 deletions

View File

@@ -30,6 +30,40 @@ class PluginInstaller
return self::$instance;
}
/**
* Decodes a plugin's associated manifest JSON.
* Returns an array of key-value pairs
*
* @param string $url
* @return array $json
*/
public function getPluginManifest(string $url): ?array
{
$options = [
'http' => [
'method' => 'GET',
'follow_location' => 1,
],
];
$context = stream_context_create($options);
$content = file_get_contents($url, false, $context);
if ($content === false) {
return null;
}
$json = json_decode($content, true);
if (json_last_error() !== JSON_ERROR_NONE) {
return null;
}
return $json;
}
/** Returns an array of installed plugins in pluginPath
*
* @return array $plugins
*/
public function getPlugins(): array
{
$plugins = [];