Class BeCallbackManager
Basic event manager for BEdita.
Methods summary
public
boolean
|
#
bind( string $eventName, mixed $listener )
Attaches a listener to an event.
Attaches a listener to an event.
Listeners can be either anonymous functions or pairs of class name (or object instance) / method name
Parameters
- $eventName
- Name of the event to be listened.
- $listener
- Callback or full qualified name of listener.
Returns
boolean Success.
See
self::callListener() to see valid types of listener
|
public
boolean
|
#
unbind( string $eventName = null, mixed $listener = null )
Detaches a listener from an event.
Detaches a listener from an event.
If $eventName is null , the given $listener will be detached from any event it was attached to.
If $listener is null , all listeners binded to the given $eventName will be detached from that event.
If both parameters are empty, each end every listener is cleared from any event.
Parameters
- $eventName
- Name of the event to be unbinded.
- $listener
- Callback or full qualified name of callback.
Returns
boolean Success.
|
public
stdClass
|
#
trigger( string $eventName, array $eventData = array() )
Triggers a new event, calling all listeners binded to that event in the order they were added.
Triggers a new event, calling all listeners binded to that event in the order they were added.
Passing data as an array will result in callbacks associated to the triggered event being called
with array elements as arguments in the order they appear in that array.
In addition to that, the $event object will be passed to those callbacks as last argument,
thus allowing listeners to gain control on event propagation or modifying the event itself.
To stop the event propagation the listener method can return false
or use $event->stopPropagation->__invoke()
Parameters
- $eventName
- Name of the event to be triggered.
- $eventData
- Data of the event.
Returns
stdClass Class representing the event triggered, with name , data , result and stopped keys.
|
private
mixed
|
#
callListener( mixed $listener, array $data = array() )
Check if $listener is valid and call it
To be valid a listener must be:
Check if $listener is valid and call it
To be valid a listener must be:
- a Closure
- a string as
ClassName::methodName (methodName should be static)
- an array as
array(instance of a class, 'methodName')
- an array as
array('ClassName', 'methodName')
In this case:
- if 'ClassName' is in the registry the instance is retrieved
- else try to use it (methodName should be static)
Parameters
- $listener
- Callback or full qualified name of callback
- $data
Returns
mixed the result of listener call
Throws
|
private
stdClass
|
#
initEvent( string $eventName, array $eventData )
Initializes a new event.
Parameters
- $eventName
- Event name.
- $eventData
- Event data.
Returns
stdClass Event.
|
Properties summary
protected
array
|
$listeners
Array of currently attached listeners.
Array of currently attached listeners.
|
|