Merge branch 'master' into 'master'

Fixing module double loading

Fix for #21

See merge request !8
This commit is contained in:
Abel Hoogeveen 2015-03-17 11:33:34 +01:00
commit 3c47d5a515

View File

@ -66,15 +66,33 @@ class Core {
## MODLOADING ## MODLOADING
public function loadMod($name, $version = null) { public function loadMod($name, $version = null) {
$CLASS = $this->loadModule($name); // Get class information
if (!isset($this->mods->{strtolower($CLASS[1])})) { $data = $this->loadModule($name, $version);
return $this->mods->{strtolower($CLASS[1])} = &$CLASS[0];
} // If it is an abstract class, create and StdClass
if (empty($data)) {
return $this->mods->{strtolower($name)} = new StdClass();
} }
public function getMod($name, $version = null) { // Otherwise load the class
$CLASS = $this->loadModule($name); $class_name = $data['className'];
return $CLASS[0];
// Create the class object if not created yet
if (!isset($this->mods->{strtolower($data['moduleLinkName'])})) {
$CLASS = new $class_name($this);
if (method_exists($CLASS, 'setModulePath')) {
$CLASS->setModulePath($data['modulePath']);
}
if (method_exists($CLASS, 'setModuleLinkName')) {
$CLASS->setModuleLinkName($data['moduleLinkName']);
}
if (method_exists($CLASS, 'setModuleName')) {
$CLASS->setModuleName($data['moduleName']);
}
$CLASS->onLoad();
return $this->mods->{strtolower($data['moduleLinkName'])} = &$CLASS;
}
} }
private function loadModule($name, $version = null) { private function loadModule($name, $version = null) {
@ -82,7 +100,6 @@ class Core {
if (!isset($this->mods->config->modregister->register)) { if (!isset($this->mods->config->modregister->register)) {
$this->buildModRegister(); $this->buildModRegister();
} else { } else {
$this->register = $this->mods->config->modregister->register; $this->register = $this->mods->config->modregister->register;
} }
@ -156,23 +173,14 @@ class Core {
if (isset($cfg->abstract)) { if (isset($cfg->abstract)) {
if ($cfg->abstract) { if ($cfg->abstract) {
$c = new stdClass(); $c = new stdClass();
return array($c, $cfg->module_name); return array();
} }
} }
// Otherwise create the class object return array('className' => $class_name,
$CLASS = new $class_name($this); 'modulePath' => $cfg->directory,
if (method_exists($CLASS, 'setModulePath')) { 'moduleLinkName' => $cfg->module_name,
$CLASS->setModulePath($cfg->directory); 'moduleName' => $name);
}
if (method_exists($CLASS, 'setModuleLinkName')) {
$CLASS->setModuleLinkName($cfg->module_name);
}
if (method_exists($CLASS, 'setModuleName')) {
$CLASS->setModuleName($name);
}
$CLASS->onLoad();
return array($CLASS, $cfg->module_name);
} }
public function buildModRegister() { public function buildModRegister() {