added unregister methods
This commit is contained in:
parent
30717ce343
commit
bebda8f69a
@ -112,6 +112,44 @@ class CallbackManager {
|
|||||||
return true;
|
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
|
* Trigger a specific callback
|
||||||
*
|
*
|
||||||
@ -249,5 +287,3 @@ class CallbackManager {
|
|||||||
$this->triggerCallback(self::CB_MC_1_MINUTE, array(self::CB_MC_1_MINUTE));
|
$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 $maniaControl = null;
|
||||||
private $commandListeners = array();
|
private $commandListeners = array();
|
||||||
private $adminCommandListeners = array();
|
private $adminCommandListeners = array();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct commands manager
|
* Construct commands manager
|
||||||
*
|
*
|
||||||
@ -32,10 +33,10 @@ class CommandManager implements CallbackListener {
|
|||||||
/**
|
/**
|
||||||
* Register a command listener
|
* Register a command listener
|
||||||
*
|
*
|
||||||
* @param string $commandName
|
* @param string $commandName
|
||||||
* @param CommandListener $listener
|
* @param CommandListener $listener
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param bool $adminCommand
|
* @param bool $adminCommand
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false) {
|
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false) {
|
||||||
@ -44,14 +45,15 @@ class CommandManager implements CallbackListener {
|
|||||||
trigger_error("Given listener can't handle command '{$command}' (no method '{$method}')!");
|
trigger_error("Given listener can't handle command '{$command}' (no method '{$method}')!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if($adminCommand){
|
if ($adminCommand) {
|
||||||
if (!array_key_exists($command, $this->adminCommandListeners) || !is_array($this->adminCommandListeners[$command])) {
|
if (!array_key_exists($command, $this->adminCommandListeners) || !is_array($this->adminCommandListeners[$command])) {
|
||||||
// Init listeners array
|
// Init admin listeners array
|
||||||
$this->adminCommandListeners[$command] = array();
|
$this->adminCommandListeners[$command] = array();
|
||||||
}
|
}
|
||||||
// Register admin command listener
|
// Register admin command listener
|
||||||
array_push($this->adminCommandListeners[$command], array($listener, $method));
|
array_push($this->adminCommandListeners[$command], array($listener, $method));
|
||||||
}else{
|
}
|
||||||
|
else {
|
||||||
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
if (!array_key_exists($command, $this->commandListeners) || !is_array($this->commandListeners[$command])) {
|
||||||
// Init listeners array
|
// Init listeners array
|
||||||
$this->commandListeners[$command] = array();
|
$this->commandListeners[$command] = array();
|
||||||
@ -62,6 +64,33 @@ class CommandManager implements CallbackListener {
|
|||||||
return true;
|
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
|
* Handle chat callback
|
||||||
*
|
*
|
||||||
@ -81,14 +110,16 @@ class CommandManager implements CallbackListener {
|
|||||||
$commandArray = explode(" ", substr($callback[1][2], 1));
|
$commandArray = explode(" ", substr($callback[1][2], 1));
|
||||||
$command = strtolower($commandArray[0]);
|
$command = strtolower($commandArray[0]);
|
||||||
|
|
||||||
if(substr($command,0,1) == "/" || $command == "admin"){ //admin command
|
if (substr($command, 0, 1) == "/" || $command == "admin") { // admin command
|
||||||
$commandListeners = $this->adminCommandListeners;
|
$commandListeners = $this->adminCommandListeners;
|
||||||
if($command == "admin"){
|
if ($command == "admin") {
|
||||||
$command = strtolower($commandArray[1]);
|
$command = strtolower($commandArray[1]);
|
||||||
}else{
|
|
||||||
$command = substr($command, 1); //remove /
|
|
||||||
}
|
}
|
||||||
}else{ //user command
|
else {
|
||||||
|
$command = substr($command, 1); // remove /
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else { // user command
|
||||||
$commandListeners = $this->commandListeners;
|
$commandListeners = $this->commandListeners;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,5 +134,3 @@ class CommandManager implements CallbackListener {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
|
||||||
|
@ -63,6 +63,20 @@ class ManialinkManager implements CallbackListener {
|
|||||||
return true;
|
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
|
* Reserve manialink ids
|
||||||
*
|
*
|
||||||
|
Loading…
Reference in New Issue
Block a user