Zend Framework  1.12
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Zend_EventManager_EventManager Class Reference

Public Member Functions

 __construct ($identifiers=null)
 Constructor.
 
 setEventClass ($class)
 Set the event class to utilize.
 
 setSharedCollections (Zend_EventManager_SharedEventCollection $collections)
 Set static collections container.
 
 unsetSharedCollections ()
 Remove any shared collections.
 
 getSharedCollections ()
 Get static collections container.
 
 getIdentifiers ()
 Get the identifier(s) for this Zend_EventManager_EventManager.
 
 setIdentifiers ($identifiers)
 Set the identifiers (overrides any currently set identifiers)
 
 addIdentifiers ($identifiers)
 Add some identifier(s) (appends to any currently set identifiers)
 
 trigger ($event, $target=null, $argv=array(), $callback=null)
 Trigger all listeners for a given event.
 
 triggerUntil ($event, $target, $argv=null, $callback=null)
 Trigger listeners until return value of one causes a callback to evaluate to true.
 
 attach ($event, $callback=null, $priority=1)
 Attach a listener to an event.
 
 attachAggregate (Zend_EventManager_ListenerAggregate $aggregate, $priority=1)
 Attach a listener aggregate.
 
 detach ($listener)
 Unsubscribe a listener from an event.
 
 detachAggregate (Zend_EventManager_ListenerAggregate $aggregate)
 Detach a listener aggregate.
 
 getEvents ()
 Retrieve all registered events.
 
 getListeners ($event)
 Retrieve all listeners for a given event.
 
 clearListeners ($event)
 Clear all listeners for a given event.
 
 prepareArgs (array $args)
 Prepare arguments.
 

Protected Member Functions

 triggerListeners ($event, Zend_EventManager_EventDescription $e, $callback=null)
 Trigger listeners.
 
 getSharedListeners ($event)
 Get list of all listeners attached to the shared collection for identifiers registered by this instance.
 
 insertListeners ($masterListeners, $listeners)
 Add listeners to the master queue of listeners.
 

Protected Attributes

 $events = array()
 
 $eventClass = 'Zend_EventManager_Event'
 
 $identifiers = array()
 
 $sharedCollections = null
 

Constructor & Destructor Documentation

__construct (   $identifiers = null)

Constructor.

Allows optionally specifying identifier(s) to use to pull signals from a StaticEventManager.

Parameters
null | string | int | array | Traversable$identifiers
Returns
void

Member Function Documentation

addIdentifiers (   $identifiers)

Add some identifier(s) (appends to any currently set identifiers)

Parameters
string | int | array | Traversable$identifiers
Returns
Zend_EventManager_EventManager
attach (   $event,
  $callback = null,
  $priority = 1 
)

Attach a listener to an event.

The first argument is the event, and the next argument describes a callback that will respond to that event. A CallbackHandler instance describing the event listener combination will be returned.

The last argument indicates a priority at which the event should be executed. By default, this value is 1; however, you may set it for any integer value. Higher values have higher priority (i.e., execute first).

You can specify "*" for the event name. In such cases, the listener will be triggered for every event.

Parameters
string | array | Zend_EventManager_ListenerAggregate$eventAn event or array of event names. If a ListenerAggregate, proxies to attachAggregate().
callback | int$callbackIf string $event provided, expects PHP callback; for a ListenerAggregate $event, this will be the priority
int$priorityIf provided, the priority at which to register the callback
Returns
Zend_Stdlib_CallbackHandler|mixed CallbackHandler if attaching callback (to allow later unsubscribe); mixed if attaching aggregate

Implements Zend_EventManager_EventCollection.

attachAggregate ( Zend_EventManager_ListenerAggregate  $aggregate,
  $priority = 1 
)

Attach a listener aggregate.

Listener aggregates accept an EventCollection instance, and call attach() one or more times, typically to attach to multiple events using local methods.

Parameters
Zend_EventManager_ListenerAggregate$aggregate
int$priorityIf provided, a suggested priority for the aggregate to use
Returns
mixed return value of Zend_EventManager_ListenerAggregate::attach()
clearListeners (   $event)

Clear all listeners for a given event.

Parameters
string$event
Returns
void

Implements Zend_EventManager_EventCollection.

detach (   $listener)

Unsubscribe a listener from an event.

Parameters
Zend_Stdlib_CallbackHandler | Zend_EventManager_ListenerAggregate$listener
Returns
bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
Exceptions
Zend_EventManager_Exception_InvalidArgumentExceptionif invalid listener provided

Implements Zend_EventManager_EventCollection.

detachAggregate ( Zend_EventManager_ListenerAggregate  $aggregate)

Detach a listener aggregate.

Listener aggregates accept an EventCollection instance, and call detach() of all previously attached listeners.

Parameters
Zend_EventManager_ListenerAggregate$aggregate
Returns
mixed return value of Zend_EventManager_ListenerAggregate::detach()
getEvents ( )

Retrieve all registered events.

Returns
array

Implements Zend_EventManager_EventCollection.

getIdentifiers ( )

Get the identifier(s) for this Zend_EventManager_EventManager.

Returns
array
getListeners (   $event)

Retrieve all listeners for a given event.

Parameters
string$event
Returns
Zend_Stdlib_PriorityQueue

Implements Zend_EventManager_EventCollection.

getSharedCollections ( )

Get static collections container.

Returns
false|Zend_EventManager_SharedEventCollection
getSharedListeners (   $event)
protected

Get list of all listeners attached to the shared collection for identifiers registered by this instance.

Parameters
string$event
Returns
array
insertListeners (   $masterListeners,
  $listeners 
)
protected

Add listeners to the master queue of listeners.

Used to inject shared listeners and wildcard listeners.

Parameters
Zend_Stdlib_PriorityQueue$masterListeners
Zend_Stdlib_PriorityQueue$listeners
Returns
void
prepareArgs ( array  $args)

Prepare arguments.

Use this method if you want to be able to modify arguments from within a listener. It returns an ArrayObject of the arguments, which may then be passed to trigger() or triggerUntil().

Parameters
array$args
Returns
ArrayObject
setEventClass (   $class)

Set the event class to utilize.

Parameters
string$class
Returns
Zend_EventManager_EventManager
setIdentifiers (   $identifiers)

Set the identifiers (overrides any currently set identifiers)

Parameters
string | int | array | Traversable$identifiers
Returns
Zend_EventManager_EventManager
setSharedCollections ( Zend_EventManager_SharedEventCollection  $collections)

Set static collections container.

Parameters
Zend_EventManager_StaticEventCollection$collections
Returns
void

Implements Zend_EventManager_SharedEventCollectionAware.

trigger (   $event,
  $target = null,
  $argv = array(),
  $callback = null 
)

Trigger all listeners for a given event.

Can emulate triggerUntil() if the last argument provided is a callback.

Parameters
string$event
string | object$targetObject calling emit, or symbol describing target (such as static method name)
array | ArrayAccess$argvArray of arguments; typically, should be associative
null | callback$callback
Returns
Zend_EventManager_ResponseCollection All listener return values

Implements Zend_EventManager_EventCollection.

triggerListeners (   $event,
Zend_EventManager_EventDescription  $e,
  $callback = null 
)
protected

Trigger listeners.

Actual functionality for triggering listeners, to which both trigger() and triggerUntil() delegate.

Parameters
string$eventEvent name
EventDescription$e
null | callback$callback
Returns
ResponseCollection
triggerUntil (   $event,
  $target,
  $argv = null,
  $callback = null 
)

Trigger listeners until return value of one causes a callback to evaluate to true.

Triggers listeners until the provided callback evaluates the return value of one as true, or until all listeners have been executed.

Parameters
string$event
string | object$targetObject calling emit, or symbol describing target (such as static method name)
array | ArrayAccess$argvArray of arguments; typically, should be associative
Callable$callback
Exceptions
Zend_Stdlib_Exception_InvalidCallbackExceptionif invalid callback provided

Implements Zend_EventManager_EventCollection.

unsetSharedCollections ( )

Remove any shared collections.

Sets $sharedCollections to boolean false to disable ability to lazy-load static event manager instance.

Returns
void

Member Data Documentation

$eventClass = 'Zend_EventManager_Event'
protected
$events = array()
protected
$identifiers = array()
protected
$sharedCollections = null
protected