Pass module model into onRegister/onUnregister
This commit is contained in:
+4
-2
@@ -2,6 +2,8 @@
|
||||
|
||||
namespace LotGD\Core;
|
||||
|
||||
use LotGD\Core\Models\Module as ModuleModel;
|
||||
|
||||
/**
|
||||
* Classes which provide module functionality should implement this interface.
|
||||
*/
|
||||
@@ -13,7 +15,7 @@ interface Module extends EventHandler
|
||||
* to the database.
|
||||
* @param Game $g The game.
|
||||
*/
|
||||
public static function onRegister(Game $g);
|
||||
public static function onRegister(Game $g, ModuleModel $module);
|
||||
|
||||
/**
|
||||
* Lifecycle method called when this module is uninstalled. Use this method
|
||||
@@ -21,5 +23,5 @@ interface Module extends EventHandler
|
||||
* during registration.
|
||||
* @param Game $g The game.
|
||||
*/
|
||||
public static function onUnregister(Game $g);
|
||||
public static function onUnregister(Game $g, ModuleModel $module);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ class ModuleManager
|
||||
}
|
||||
|
||||
// Run the module's onRegister handler.
|
||||
$class::onRegister($this->g);
|
||||
$class::onRegister($this->g, $m);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,9 +93,6 @@ class ModuleManager
|
||||
if (!$m) {
|
||||
throw new ModuleDoesNotExistException($name);
|
||||
} else {
|
||||
// TODO: handle error cases here.
|
||||
$m->delete($this->g->getEntityManager());
|
||||
|
||||
$class = $library->getRootNamespace() . 'Module';
|
||||
|
||||
// Unsubscribe the module's events.
|
||||
@@ -109,7 +106,10 @@ class ModuleManager
|
||||
}
|
||||
|
||||
// Run the module's onUnregister handler.
|
||||
$class::onUnregister($this->g);
|
||||
$class::onUnregister($this->g, $m);
|
||||
|
||||
// TODO: handle error cases here.
|
||||
$m->delete($this->g->getEntityManager());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,13 +3,14 @@
|
||||
namespace LotGD\Core\Tests\FakeModule;
|
||||
|
||||
use LotGD\Core\Game;
|
||||
use LotGD\Core\Module as ModuleBase;
|
||||
use LotGD\Core\Module as ModuleInterface;
|
||||
use LotGD\Core\Models\Module as ModuleModel;
|
||||
|
||||
class Module implements ModuleBase {
|
||||
class Module implements ModuleInterface {
|
||||
public static function handleEvent(Game $g, string $event, array &$context) {
|
||||
$context['foo'] = 'baz';
|
||||
return $context;
|
||||
}
|
||||
public static function onRegister(Game $g) {}
|
||||
public static function onUnregister(Game $g) {}
|
||||
public static function onRegister(Game $g, ModuleModel $module) {}
|
||||
public static function onUnregister(Game $g, ModuleModel $module) {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user