mirror of
https://github.com/mivodev/mivo.git
synced 2026-01-26 21:41:59 +07:00
feat: Implement a core plugin system, integrate flag icon assets, and establish a GitHub release workflow.
This commit is contained in:
78
app/Core/PluginManager.php
Normal file
78
app/Core/PluginManager.php
Normal file
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Core;
|
||||
|
||||
class PluginManager
|
||||
{
|
||||
/**
|
||||
* @var string Path to plugins directory
|
||||
*/
|
||||
private $pluginsDir;
|
||||
|
||||
/**
|
||||
* @var array List of active plugins
|
||||
*/
|
||||
private $activePlugins = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->pluginsDir = dirname(__DIR__, 2) . '/plugins'; // Root/plugins
|
||||
}
|
||||
|
||||
/**
|
||||
* Load all active plugins
|
||||
*/
|
||||
public function loadPlugins()
|
||||
{
|
||||
// Ensure plugins directory exists
|
||||
if (!is_dir($this->pluginsDir)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 1. Get List of Active Plugins (For now, we load ALL folders as active)
|
||||
// TODO: Implement database/config check for active status
|
||||
$plugins = scandir($this->pluginsDir);
|
||||
|
||||
foreach ($plugins as $pluginName) {
|
||||
if ($pluginName === '.' || $pluginName === '..') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$pluginPath = $this->pluginsDir . '/' . $pluginName;
|
||||
|
||||
// Check if it is a directory and has specific plugin file
|
||||
if (is_dir($pluginPath) && file_exists($pluginPath . '/plugin.php')) {
|
||||
$this->loadPlugin($pluginName, $pluginPath);
|
||||
}
|
||||
}
|
||||
|
||||
// Fire 'plugins_loaded' action after all plugins are loaded
|
||||
Hooks::doAction('plugins_loaded');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a single plugin
|
||||
*
|
||||
* @param string $name Plugin folder name
|
||||
* @param string $path Full path to plugin directory
|
||||
*/
|
||||
private function loadPlugin($name, $path)
|
||||
{
|
||||
try {
|
||||
require_once $path . '/plugin.php';
|
||||
$this->activePlugins[] = $name;
|
||||
} catch (\Exception $e) {
|
||||
error_log("Failed to load plugin [$name]: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of loaded plugins
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getActivePlugins()
|
||||
{
|
||||
return $this->activePlugins;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user