Zend Framework  3.0
Public Member Functions | List of all members
EventManagerInterface Interface Reference

Interface for messengers. More...

Public Member Functions

 trigger ($eventName, $target=null, $argv=[])
 Create and trigger an event.
 
 triggerUntil (callable $callback, $eventName, $target=null, $argv=[])
 Create and trigger an event, applying a callback to each listener result.
 
 triggerEvent (EventInterface $event)
 Trigger an event.
 
 triggerEventUntil (callable $callback, EventInterface $event)
 Trigger an event, applying a callback to each listener result.
 
 attach ($eventName, callable $listener, $priority=1)
 Attach a listener to an event.
 
 detach (callable $listener, $eventName=null)
 Detach a listener.
 
 clearListeners ($eventName)
 Clear all listeners for a given event.
 
 setEventPrototype (EventInterface $prototype)
 Provide an event prototype to use with trigger().
 
 getIdentifiers ()
 Get the identifier(s) for this EventManager.
 
 setIdentifiers (array $identifiers)
 Set the identifiers (overrides any currently set identifiers)
 
 addIdentifiers (array $identifiers)
 Add identifier(s) (appends to any currently set identifiers)
 
- Public Member Functions inherited from SharedEventsCapableInterface
 getSharedManager ()
 Retrieve the shared event manager, if composed.
 

Detailed Description

Interface for messengers.

Member Function Documentation

addIdentifiers ( array  $identifiers)

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

Parameters
string[]$identifiers
Returns
void

Implemented in EventManager.

attach (   $eventName,
callable  $listener,
  $priority = 1 
)

Attach a listener to an event.

The first argument is the event, and the next argument is a callable that will respond to that event.

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 *that has registered listeners at the time it is attached*. As such, register wildcard events last whenever possible!

Parameters
string$eventNameEvent to which to listen.
callable$listener
int$priorityPriority at which to register listener.
Returns
callable

Implemented in EventManager, and AbstractValidatorChainEM3.

clearListeners (   $eventName)

Clear all listeners for a given event.

Parameters
string$eventName
Returns
void

Implemented in EventManager.

detach ( callable  $listener,
  $eventName = null 
)

Detach a listener.

If no $event or '*' is provided, detaches listener from all events; otherwise, detaches only from the named event.

Parameters
callable$listener
null | string$eventNameEvent from which to detach; null and '*' indicate all events.
Returns
void
getIdentifiers ( )

Get the identifier(s) for this EventManager.

Returns
array

Implemented in EventManager.

setEventPrototype ( EventInterface  $prototype)

Provide an event prototype to use with trigger().

When `trigger()` needs to create an event instance, it should clone the prototype provided to this method.

Parameters
EventInterface$prototype
Returns
void

Implemented in EventManager.

setIdentifiers ( array  $identifiers)

Set the identifiers (overrides any currently set identifiers)

Parameters
string[]$identifiers
Returns
void

Implemented in EventManager.

trigger (   $eventName,
  $target = null,
  $argv = [] 
)

Create and trigger an event.

Use this method when you do not want to create an EventInterface instance prior to triggering. You will be required to pass:

  • the event name
  • the event target (can be null)
  • any event parameters you want to provide (empty array by default)

It will create the Event instance for you and then trigger all listeners related to the event.

Parameters
string$eventName
null | object | string$target
array | object$argv
Returns
ResponseCollection

Implemented in EventManager.

triggerEvent ( EventInterface  $event)

Trigger an event.

Provided an EventInterface instance, this method will trigger listeners based on the event name, raising an exception if the event name is missing.

Parameters
EventInterface$event
Returns
ResponseCollection

Implemented in EventManager.

triggerEventUntil ( callable  $callback,
EventInterface  $event 
)

Trigger an event, applying a callback to each listener result.

Provided an EventInterface instance, this method will trigger listeners based on the event name, raising an exception if the event name is missing.

The result of each listener is passed to $callback; if $callback returns a boolean true value, the manager must short-circuit listener execution.

Parameters
callable$callback
EventInterface$event
Returns
ResponseCollection

Implemented in EventManager.

triggerUntil ( callable  $callback,
  $eventName,
  $target = null,
  $argv = [] 
)

Create and trigger an event, applying a callback to each listener result.

Use this method when you do not want to create an EventInterface instance prior to triggering. You will be required to pass:

  • the event name
  • the event target (can be null)
  • any event parameters you want to provide (empty array by default)

It will create the Event instance for you, and trigger all listeners related to the event.

The result of each listener is passed to $callback; if $callback returns a boolean true value, the manager must short-circuit listener execution.

Parameters
callable$callback
string$eventName
null | object | string$target
array | object$argv
Returns
ResponseCollection

Implemented in EventManager.