KWeb  6.4
FunctionProxy Class Reference

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

Detailed Description

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');

*

See also:
__construct for details

Constructor & Destructor Documentation

FunctionProxy::__construct ( callable,
arguments = null,
argumentsMap = null 
)
Parameters:
string | array | Closure | object$callableAnything that is callable. Calling methods on objects, from source call arguments is supported only for string and array callables.
array | null$argumentsList of arguments to pass to the callable. Use null to pass arguments from the source call.
array | null$argumentsMapMapping of arguments from source call, to destination call as:
source_argument_index => destination_argument_index


Member Function Documentation

FunctionProxy::__invoke ( )
static FunctionProxy::create ( callable,
arguments = null,
argumentsMap = null 
) [static]
FunctionProxy::getCallable ( )

Field Documentation

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.


The documentation for this class was generated from the following file: