New:Introducing Socket Scanning for VS Code Marketplace Extensions.Learn more →
Get Started

actualwave/callbacks

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

actualwave/callbacks

Family of callback wrappers with shared interface

Source
Packagist
Version
0.0.4
Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

##PHP-Callbacks Build Status Coverage Status Dependency Status

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; // new value

function doEcho($param){
  echo 'My name is: '.$param.PHP_EOL;
}

$callback = new \aw\callbacks\FunctionCallback('doEcho');
$callback('####'); // My name is: ####

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; // Result: 48

Keywords

object

FAQs

Package last updated on 05 Jan 2016

Related posts