added unregister methods
This commit is contained in:
parent
30717ce343
commit
bebda8f69a
@ -112,6 +112,44 @@ class CallbackManager {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Callback Listener
|
||||
*
|
||||
* @param CallbackListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
public function unregisterCallbackListener(CallbackListener $listener) {
|
||||
$removed = false;
|
||||
foreach ($this->callbackListeners as &$listeners) {
|
||||
foreach ($listeners as $key => &$listenerCallback) {
|
||||
if ($listenerCallback[0] == $listener) {
|
||||
unset($listeners[$key]);
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Script Callback Listener
|
||||
*
|
||||
* @param CallbackListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
public function unregisterScriptCallbackListener(CallbackListener $listener) {
|
||||
$removed = false;
|
||||
foreach ($this->scriptCallbackListener as &$listeners) {
|
||||
foreach ($listeners as $key => &$listenerCallback) {
|
||||
if ($listenerCallback[0] == $listener) {
|
||||
unset($listeners[$key]);
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Trigger a specific callback
|
||||
*
|
||||
@ -249,5 +287,3 @@ class CallbackManager {
|
||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -19,6 +19,7 @@ class CommandManager implements CallbackListener {
|
||||
private $maniaControl = null;
|
||||
private $commandListeners = array();
|
||||
private $adminCommandListeners = array();
|
||||
|
||||
/**
|
||||
* Construct commands manager
|
||||
*
|
||||
@ -46,12 +47,13 @@ class CommandManager implements CallbackListener {
|
||||
}
|
||||
if ($adminCommand) {
|
||||
if (!array_key_exists($command, $this->adminCommandListeners) || !is_array($this->adminCommandListeners[$command])) {
|
||||
// Init listeners array
|
||||
// Init admin listeners array
|
||||
$this->adminCommandListeners[$command] = array();
|
||||
}
|
||||
// Register admin command listener
|
||||
array_push($this->adminCommandListeners[$command], array($listener, $method));
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
||||
// Init listeners array
|
||||
$this->commandListeners[$command] = array();
|
||||
@ -62,6 +64,33 @@ class CommandManager implements CallbackListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Command Listener
|
||||
*
|
||||
* @param CommandListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
public function unregisterCommandListener(CommandListener $listener) {
|
||||
$removed = false;
|
||||
foreach ($this->commandListeners as &$listeners) {
|
||||
foreach ($listeners as $key => &$listenerCallback) {
|
||||
if ($listenerCallback[0] == $listener) {
|
||||
unset($listeners[$key]);
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
foreach ($this->adminCommandListeners as &$listeners) {
|
||||
foreach ($listeners as $key => &$listenerCallback) {
|
||||
if ($listenerCallback[0] == $listener) {
|
||||
unset($listeners[$key]);
|
||||
$removed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $removed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle chat callback
|
||||
*
|
||||
@ -85,10 +114,12 @@ class CommandManager implements CallbackListener {
|
||||
$commandListeners = $this->adminCommandListeners;
|
||||
if ($command == "admin") {
|
||||
$command = strtolower($commandArray[1]);
|
||||
}else{
|
||||
}
|
||||
else {
|
||||
$command = substr($command, 1); // remove /
|
||||
}
|
||||
}else{ //user command
|
||||
}
|
||||
else { // user command
|
||||
$commandListeners = $this->commandListeners;
|
||||
}
|
||||
|
||||
@ -103,5 +134,3 @@ class CommandManager implements CallbackListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -63,6 +63,20 @@ class ManialinkManager implements CallbackListener {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a Manialink Page Answer Listener
|
||||
*
|
||||
* @param ManialinkPageAnswerListener $listener
|
||||
* @return bool
|
||||
*/
|
||||
public function unregisterManialinkPageAnswerListener(ManialinkPageAnswerListener $listener) {
|
||||
$keys = array_keys($this->pageAnswerListeners, $listener);
|
||||
foreach ($keys as $key) {
|
||||
unset($this->pageAnswerListeners[$key]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reserve manialink ids
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user