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