Zend Framework  2.4
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
EventManager Class Reference

Event manager: notification system. More...

Public Member Functions

 __construct ($identifiers=null)
 Constructor.
 
 setEventClass ($class)
 Set the event class to utilize.
 
 setSharedManager (SharedEventManagerInterface $sharedEventManager)
 Set shared event manager.
 
 unsetSharedManager ()
 Remove any shared event manager currently attached.
 
 getSharedManager ()
 Get shared event manager.
 
 getIdentifiers ()
 Get the identifier(s) for this 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 (ListenerAggregateInterface $aggregate, $priority=1)
 Attach a listener aggregate.
 
 detach ($listener)
 Unsubscribe a listener from an event.
 
 detachAggregate (ListenerAggregateInterface $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, EventInterface $e, $callback=null)
 Trigger listeners.
 
 getSharedListeners ($event)
 Get list of all listeners attached to the shared event manager 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()
 
 $sharedManager = null
 

Detailed Description

Event manager: notification system.

Use the EventManager when you want to create a per-instance notification system for your objects.

Constructor & Destructor Documentation

__construct (   $identifiers = null)

Constructor.

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

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

Member Function Documentation

addIdentifiers (   $identifiers)

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

Parameters
string | int | array | Traversable$identifiers
Returns
EventManager Provides a fluent interface

Implements EventManagerInterface.

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 | ListenerAggregateInterface$eventAn event or array of event names. If a ListenerAggregateInterface, proxies to attachAggregate().
callable | int$callbackIf string $event provided, expects PHP callback; for a ListenerAggregateInterface $event, this will be the priority
int$priorityIf provided, the priority at which to register the callable
Returns
CallbackHandler|mixed CallbackHandler if attaching callable (to allow later unsubscribe); mixed if attaching aggregate
Exceptions
Exception\InvalidArgumentException

Implements EventManagerInterface.

attachAggregate ( ListenerAggregateInterface  $aggregate,
  $priority = 1 
)

Attach a listener aggregate.

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

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

Implements EventManagerInterface.

clearListeners (   $event)

Clear all listeners for a given event.

Parameters
string$event
Returns
void

Implements EventManagerInterface.

detach (   $listener)

Unsubscribe a listener from an event.

Parameters
CallbackHandler | ListenerAggregateInterface$listener
Returns
bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
Exceptions
Exception\InvalidArgumentExceptionif invalid listener provided

Implements EventManagerInterface.

detachAggregate ( ListenerAggregateInterface  $aggregate)

Detach a listener aggregate.

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

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

Implements EventManagerInterface.

getEvents ( )

Retrieve all registered events.

Returns
array

Implements EventManagerInterface.

getIdentifiers ( )

Get the identifier(s) for this EventManager.

Returns
array

Implements EventManagerInterface.

getListeners (   $event)

Retrieve all listeners for a given event.

Parameters
string$event
Returns
PriorityQueue

Implements EventManagerInterface.

getSharedListeners (   $event)
protected

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

Parameters
string$event
Returns
array
getSharedManager ( )

Get shared event manager.

If one is not defined, but we have a static instance in StaticEventManager, that one will be used and set in this instance.

If none is available in the StaticEventManager, a boolean false is returned.

Returns
false|SharedEventManagerInterface

Implements SharedEventManagerAwareInterface.

insertListeners (   $masterListeners,
  $listeners 
)
protected

Add listeners to the master queue of listeners.

Used to inject shared listeners and wildcard listeners.

Parameters
PriorityQueue$masterListeners
array | Traversable$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().

Parameters
array$args
Returns
ArrayObject
setEventClass (   $class)

Set the event class to utilize.

Parameters
string$class
Returns
EventManager

Implements EventManagerInterface.

setIdentifiers (   $identifiers)

Set the identifiers (overrides any currently set identifiers)

Parameters
string | int | array | Traversable$identifiers
Returns
EventManager Provides a fluent interface

Implements EventManagerInterface.

setSharedManager ( SharedEventManagerInterface  $sharedEventManager)

Set shared event manager.

Parameters
SharedEventManagerInterface$sharedEventManager
Returns
EventManager

Implements SharedEventManagerAwareInterface.

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

Trigger all listeners for a given event.

Parameters
string | EventInterface$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 | callable$callbackTrigger listeners until return value of this callback evaluate to true
Returns
ResponseCollection All listener return values
Exceptions
Exception\InvalidCallbackException

Implements EventManagerInterface.

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

Trigger listeners.

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

Parameters
string$eventEvent name
EventInterface$e
null | callable$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 | EventInterface$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
Returns
ResponseCollection
Deprecated:
Please use trigger()
Exceptions
Exception\InvalidCallbackExceptionif invalid callable provided

Implements EventManagerInterface.

unsetSharedManager ( )

Remove any shared event manager currently attached.

Returns
void

Implements SharedEventManagerAwareInterface.

Member Data Documentation

$eventClass = 'Zend\EventManager\Event'
protected
$events = array()
protected
$identifiers = array()
protected
$sharedManager = null
protected