Class Delegate
A delegate is a collection of callbacks that are invoked sequentially when
the delegate itself is invoked.
-
Core\Object
implements
Core\Chainable
-
Core\Set
implements
Core\Accessor
-
Core\Delegate
Namespace: Core
Package: Core
Since:
3.0
Requires:
PHP 5.3
Version:
1.1
Located at Delegate.inc.php
Methods summary
public
mixed
|
#
__invoke( )
Invokes all registered callbacks. Parameters are passed verbatim to
the registered callbacks; all parameters are passed by value due to
restrictions of the PHP engine. If parameters need to be modified by
the invoked callback, use objects instead which are always passed by
as references. Use Core\Delegate::invokeWithArguments() to pass arguments by
reference.
Invokes all registered callbacks. Parameters are passed verbatim to
the registered callbacks; all parameters are passed by value due to
restrictions of the PHP engine. If parameters need to be modified by
the invoked callback, use objects instead which are always passed by
as references. Use Core\Delegate::invokeWithArguments() to pass arguments by
reference.
Returns
mixed Return value of last callback.
Remark
Callbacks are invoked in exactly the same order they have been
registered.
Hence the PHP engine does not allow to dynamically retrieve a variable
list of argument references, arguments can only be passed by value to
the callback. Use objects if the callback is required to modify an
argument.
See
Since
3.0
|
public
|
#
add( mixed $objectOrCallable, string $methodName = null )
Registers a new callback.
Registers a new callback.
Parameters
- $objectOrCallable
Either a callable or an object or class name that combined with the
method name argument forms a callable.
- $methodName
- Name of method if first argument is an object or class name.
Returns
$this
Throws
Remark
Registering the same callback multiple times is possible. The callback
will accordingly be invoked multiple times.
See
Since
3.0
|
public
mixed
|
#
invoke( )
Invokes all registered callbacks. Parameters are passed verbatim to
the registered callbacks; all parameters are passed by value due to
restrictions of the PHP engine. If parameters need to be modified by
the invoked callback, use objects instead which are always passed by
as references. Use Core\Delegate::invokeWithArguments() to pass arguments by
reference.
Invokes all registered callbacks. Parameters are passed verbatim to
the registered callbacks; all parameters are passed by value due to
restrictions of the PHP engine. If parameters need to be modified by
the invoked callback, use objects instead which are always passed by
as references. Use Core\Delegate::invokeWithArguments() to pass arguments by
reference.
Returns
mixed Return value of last callback.
Remark
Callbacks are invoked in exactly the same order they have been
registered.
Hence the PHP engine does not allow to dynamically retrieve a variable
list of argument references, arguments can only be passed by value to
the callback. Use objects if the callback is required to modify an
argument.
See
Since
3.0
|
public
mixed
|
#
invokeWithArguments( array $arguments = null, callable $invocationCallback = null )
Invokes all registered callbacks. Parameters are passed as an array,
which allows the delegate to pass arguments as references to the
registered callbacks. Use an ampersand ("& ") prefix for variables in
the supplied array to declare those as references:
Invokes all registered callbacks. Parameters are passed as an array,
which allows the delegate to pass arguments as references to the
registered callbacks. Use an ampersand ("& ") prefix for variables in
the supplied array to declare those as references:
$delegate->invokeWithArguments (array ($a, &$b, $object));
In the example code, scalar a is passed by value whereas scalar b
is passed by reference. The object is always passed by reference.
Parameters
- $arguments
- Optional array of arguments to pass to callbacks.
- $invocationCallback
Optional callback method called after each callback invoked to evaluate
the return value of the callback. If this value is null , all callbacks
are invoked regardless of their return value and the last return value
is returned, as in Core\Delegate::invoke() .
The callback must accept exactly two argument: An index and the return
value of the invoked callback. The index is the iteration invariant over
the number of callbacks registered with the delegate. If the callback
returns false , the execution of callbacks is stopped and the last
return value is returned. The callback may also modify the return value
by accepting the argument as a reference and then modify its value; the
modified value will be returned instead.
Returns
mixed Return value of last callback.
Remark
Callbacks are invoked in exactly the same order they have been
registered.
See
Since
3.1
|
public
boolean
|
#
remove( mixed $objectOrCallable, string $methodName = null )
Removes a callback from the delegate.
Removes a callback from the delegate.
Parameters
- $objectOrCallable
Either a callable or an object or class name that combined with the
method name argument forms a callable.
- $methodName
- Name of method if first argument is an object or class name.
Returns
boolean
true on successful removal or false , if the callback was not found.
Remark
Multiple registrations of the same callback require multiple releases
of the callback. Each call removes the first matching callback list entry.
See
Since
3.1
|
__autocreateFactory()
,
__call()
,
__processParameters()
,
__toString()
,
attachMethod()
,
chain()
,
getValueForKey()
,
getValueForKeyPath()
,
getValueForUndefinedKey()
,
hash()
,
issetValueForKey()
,
setValueForKey()
,
setValueForKeyPath()
,
setValueForUndefinedKey()
,
uuid()
Properties summary
protected
callable[]
|
$_v_callbacks
Array of registered callbacks.
Array of registered callbacks.
Since
3.0
|
|