improved plugin files loading

This commit is contained in:
Steffen Schröder 2014-02-15 15:57:08 +01:00
parent a2af53f5f8
commit 99b7e1464f

View File

@ -180,53 +180,67 @@ class PluginManager {
return true; return true;
} }
/** /**
* Load complete plugins directory and start all configured plugins * Load complete Plugins Directory and start all configured Plugins
*/ */
public function loadPlugins($dir = '') { public function loadPlugins() {
//TODO first include all files, than handle plugin activation $pluginsDirectory = ManiaControlDir . '/plugins/';
$pluginsDirectory = ManiaControlDir . '/plugins/' . $dir . '/';
$pluginFiles = scandir($pluginsDirectory, 0);
foreach($pluginFiles as $pluginFile) {
if (stripos($pluginFile, '.') === 0) {
continue;
}
if (is_dir($pluginsDirectory . $pluginFile)) {
$this->loadPlugins($pluginFile);
continue;
}
$classesBefore = get_declared_classes(); $classesBefore = get_declared_classes();
$success = include_once $pluginsDirectory . $pluginFile; $this->loadPluginFiles($pluginsDirectory);
if (!$success) {
continue;
}
$classesAfter = get_declared_classes(); $classesAfter = get_declared_classes();
$newClasses = array_diff($classesAfter, $classesBefore); $newClasses = array_diff($classesAfter, $classesBefore);
foreach($newClasses as $className) { foreach($newClasses as $className) {
if (!$this->isPluginClass($className)) { if (!$this->isPluginClass($className)) {
continue; continue;
} }
//Prepare Plugin $this->addPluginClass($className);
$className::prepare($this->maniaControl); $className::prepare($this->maniaControl);
$this->addPluginClass($className);
if ($this->isPluginActive($className)) { if ($this->isPluginActive($className)) {
continue; continue;
} }
if (!$this->getSavedPluginStatus($className)) { if (!$this->getSavedPluginStatus($className)) {
continue; continue;
} }
$this->activatePlugin($className); $this->activatePlugin($className);
} }
} }
/**
* Load all Plugin Files from the Directory
*
* @param string $directory
*/
private function loadPluginFiles($directory = '') {
$pluginFiles = scandir($directory);
foreach ($pluginFiles as $pluginFile) {
if (stripos($pluginFile, '.') === 0) {
continue;
}
$filePath = $directory . $pluginFile;
if (is_file($filePath)) {
$success = include_once $filePath;
if (!$success) {
trigger_error("Error loading File '{$filePath}'!");
}
continue;
}
$dirPath = $directory . $pluginFile;
if (is_dir($dirPath)) {
$this->loadPluginFiles($dirPath . '/');
continue;
}
}
} }
/** /**
* Returns an Plugin if it is activated * Returns a Plugin if it is activated
* *
* @param string $pluginClass * @param string $pluginClass
* @return Plugin * @return Plugin