KWeb
6.4
|
Creates a callable function poxy, that replaces, or remaps call arguments. More...
Public Member Functions | |
__construct ($callable, $arguments=null, $argumentsMap=null) | |
__invoke () | |
getCallable () | |
Static Public Member Functions | |
static | create ($callable, $arguments=null, $argumentsMap=null) |
Data Fields | |
const | CALL_OBJECT = 'object' |
Map this argument as the calling object. | |
const | CALL_CLASS = 'class' |
Map this argument as the calling class. | |
const | ARG_REST = 'rest' |
Map all arguments, starting from here, to the destination by appending the current list of arguments. | |
Static Public Attributes | |
static | $invokeSupported = false |
Protected Attributes | |
$callable | |
$arguments | |
$argumentsMap |
Creates a callable function poxy, that replaces, or remaps call arguments.
It's also possible to call methods on objects, that where passed to the source call.
source_call --> argument_remapping --> destination_call
On PHP5.3 you can use directly new FunctionProxy directly. On PHP 5.2 you have to use getCallable(). For best results use FunctionProxy::create() which will return object or callable array depending on platform.
Usage:
simple proxy, that passes call arguments to callback
function func($a, $b) {} $proxy = FunctionProxy::create('func'); $proxy('a', 'b');
simple proxy, that passes proxy variables
function func($C) {} $proxy = FunctionProxy::create('func', array('C')); $proxy('a', 'b');
mapping variables using proxy. Call arguments are mapped to first and third callback argument
function func($a, $C, $b) {} $proxy = FunctionProxy::create('func', array(null, 'C', null), array(0 => 0, 1 => 2)); $proxy('a', 'b');
mapping arguments and caller using proxy. First call argument is used as object to call the callback on. Second is passed as first argument in callback. The rest of the call arguments is passed at the end.
class someClass { function func($a, $SOME, $b, $c, $d) {} } $object = new someClass(); $proxy = FunctionProxy::create(array(null, 'func'), array(null, 'SOME'), array(0 => FunctionProxy::CALL_OBJECT, 1 => 0, 2 => FunctionProxy::ARG_REST)); $proxy($object, 'a', 'b', 'c', 'd');
*
string | array | Closure | object | $callable | Anything that is callable. Calling methods on objects, from source call arguments is supported only for string and array callables. |
array | null | $arguments | List of arguments to pass to the callable. Use null to pass arguments from the source call. |
array | null | $argumentsMap | Mapping of arguments from source call, to destination call as: source_argument_index => destination_argument_index |
FunctionProxy::__invoke | ( | ) |
FunctionProxy::getCallable | ( | ) |
FunctionProxy::$arguments [protected] |
FunctionProxy::$argumentsMap [protected] |
FunctionProxy::$callable [protected] |
FunctionProxy::$invokeSupported = false [static] |
const FunctionProxy::ARG_REST = 'rest' |
Map all arguments, starting from here, to the destination by appending the current list of arguments.
const FunctionProxy::CALL_CLASS = 'class' |
Map this argument as the calling class.
const FunctionProxy::CALL_OBJECT = 'object' |
Map this argument as the calling object.