##PHP-Callbacks

Family of Callback Wrappers allowing to store chains of delayed calls that can be started by event.
- FunctionCallback - calls global function or static method.
- MethodCallback - calls instance or static method.
- OutputCallback - outputs all arguments in JSON format.
- PropertyCallback - stores first argument as property value, works with static properties.
- VariableCallback - stores first argument as variable value, works with static properties.
- CallableQueue - calls stored callbacks passing previous result as argument, returns result of last callback.
- CallableSequence - calls stored callbacks with same arguments, returns result of last callback.
$variable = 'value';
$callback = new \aw\callbacks\VariableCallback('variable');
$callback('new value');
echo $variable.PHP_EOL;
function doEcho($param){
echo 'My name is: '.$param.PHP_EOL;
}
$callback = new \aw\callbacks\FunctionCallback('doEcho');
$callback('####');
All wrappers are callables, so can be used directly as closure.
CallableCollection accepts any callable including PHP closures.
function multiply4($value){
return $value*4;
}
$collection = new \aw\CallableQueue();
$collection[] = function($value){
return $value*2;
};
$collection[] = function($value){
return $value*3;
};
$collection[] = new \aw\callbacks\FunctionCallback('multiply4');
echo 'Result: '.$collection(2).PHP_EOL;