From facddb0d6d13ab7a492340e5ed69d044c6286233 Mon Sep 17 00:00:00 2001 From: Yasen Pramatarov Date: Thu, 24 Apr 2025 13:25:03 +0300 Subject: [PATCH] Adds PluginManager core class --- app/core/PluginManager.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/core/PluginManager.php diff --git a/app/core/PluginManager.php b/app/core/PluginManager.php new file mode 100644 index 0000000..dd8492e --- /dev/null +++ b/app/core/PluginManager.php @@ -0,0 +1,37 @@ + + */ + public static function load(string $pluginsDir): array + { + $enabled = []; + foreach (glob($pluginsDir . '*', GLOB_ONLYDIR) as $pluginPath) { + $manifest = $pluginPath . '/plugin.json'; + if (!file_exists($manifest)) { + continue; + } + $meta = json_decode(file_get_contents($manifest), true); + if (empty($meta['enabled'])) { + continue; + } + $name = basename($pluginPath); + $enabled[$name] = [ + 'path' => $pluginPath, + 'meta' => $meta, + ]; + $bootstrap = $pluginPath . '/bootstrap.php'; + if (file_exists($bootstrap)) { + include_once $bootstrap; + } + } + return $enabled; + } +}