added possability to set a Method to call in your class

This commit is contained in:
kremsy 2017-04-07 18:45:59 +02:00
parent 28f60a1ddb
commit dcfb3fb9ec

View File

@ -45,13 +45,27 @@ class InvokeScriptCallback implements CallbackListener, UsageInformationAble {
* @param callable $function async Function to Call back * @param callable $function async Function to Call back
*/ */
public function setCallable(callable $function) { public function setCallable(callable $function) {
$this->maniaControl->getCallbackManager()->registerCallbackListener($this->callbackName, $this, function(BaseResponseStructure $callBackData) use (&$function){ $this->maniaControl->getCallbackManager()->registerCallbackListener($this->callbackName, $this, function (BaseResponseStructure $callBackData) use (&$function) {
if($callBackData->getResponseId() == $this->responseId){ if ($callBackData->getResponseId() == $this->responseId) {
call_user_func_array($function, array($callBackData)); call_user_func_array($function, array($callBackData));
} }
}); });
} }
/**
* You can set a Method in your Class to be called with this Variant
*
* @param \ManiaControl\Callbacks\CallbackListener $callbackListener
* @param $methodName
*/
public function setCallableMethod(CallbackListener $callbackListener, $methodName) {
$this->maniaControl->getCallbackManager()->registerCallbackListener($this->callbackName, $this, function (BaseResponseStructure $callBackData) use (&$callbackListener, &$methodName) {
if ($callBackData->getResponseId() == $this->responseId) {
call_user_func_array(array($callbackListener, $methodName), array($callBackData));
}
});
}
/** /**
* Returns the Generated ResponseId * Returns the Generated ResponseId
* *