487. Class

487.1. Zend\EventManager\EventManager

Event manager: notification system

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

487.1.1. Methods

487.1.1.1. __construct

__construct()

Constructor

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

Parameters:null|string|int|array|Traversable

487.1.1.2. setEventClass

setEventClass()

Set the event class to utilize

Parameters:string
Return type:EventManager

487.1.1.3. setSharedManager

setSharedManager()

Set shared event manager

Parameters:SharedEventManagerInterface
Return type:EventManager

487.1.1.4. unsetSharedManager

unsetSharedManager()

Remove any shared event manager currently attached

Return type:void

487.1.1.5. getSharedManager

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.

Return type:false|SharedEventManagerInterface

487.1.1.6. getIdentifiers

getIdentifiers()

Get the identifier(s) for this EventManager

Return type:array

487.1.1.7. setIdentifiers

setIdentifiers()

Set the identifiers (overrides any currently set identifiers)

Parameters:string|int|array|Traversable
Return type:EventManager Provides a fluent interface

487.1.1.8. addIdentifiers

addIdentifiers()

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

Parameters:string|int|array|Traversable
Return type:EventManager Provides a fluent interface

487.1.1.9. trigger

trigger()

Trigger all listeners for a given event

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

Parameters:
  • string
  • string|object – Object calling emit, or symbol describing target (such as static method name)
  • array|ArrayAccess – Array of arguments; typically, should be associative
  • null|callable
Return type:

ResponseCollection All listener return values

Throws :

ExceptionInvalidCallbackException

487.1.1.10. triggerUntil

triggerUntil()

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
  • string|object – Object calling emit, or symbol describing target (such as static method name)
  • array|ArrayAccess – Array of arguments; typically, should be associative
  • callable
Return type:

ResponseCollection

Throws :

ExceptionInvalidCallbackException if invalid callable provided

487.1.1.11. attach

attach()

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 – An event or array of event names. If a ListenerAggregateInterface, proxies to {@link attachAggregate()}.
  • callable|int – If string $event provided, expects PHP callback; for a ListenerAggregateInterface $event, this will be the priority
  • int – If provided, the priority at which to register the callable
Return type:

CallbackHandler|mixed CallbackHandler if attaching callable (to allow later unsubscribe); mixed if attaching aggregate

Throws :

ExceptionInvalidArgumentException

487.1.1.12. attachAggregate

attachAggregate()

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
  • int – If provided, a suggested priority for the aggregate to use
Return type:

mixed return value of {@link ListenerAggregateInterface::attach()}

487.1.1.13. detach

detach()

Unsubscribe a listener from an event

Parameters:CallbackHandler|ListenerAggregateInterface
Return type:bool Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found
Throws :ExceptionInvalidArgumentException if invalid listener provided

487.1.1.14. detachAggregate

detachAggregate()

Detach a listener aggregate

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

Parameters:ListenerAggregateInterface
Return type:mixed return value of {@link ListenerAggregateInterface::detach()}

487.1.1.15. getEvents

getEvents()

Retrieve all registered events

Return type:array

487.1.1.16. getListeners

getListeners()

Retrieve all listeners for a given event

Parameters:string
Return type:PriorityQueue

487.1.1.17. clearListeners

clearListeners()

Clear all listeners for a given event

Parameters:string
Return type:void

487.1.1.18. prepareArgs

prepareArgs()

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
Return type:ArrayObject

487.1.1.19. triggerListeners

triggerListeners()

Trigger listeners

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

Parameters:
  • string – Event name
  • EventInterface
  • null|callable
Return type:

ResponseCollection

487.1.1.20. getSharedListeners

getSharedListeners()

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

Parameters:string
Return type:array

487.1.1.21. insertListeners

insertListeners()

Add listeners to the master queue of listeners

Used to inject shared listeners and wildcard listeners.

Parameters:
  • PriorityQueue
  • PriorityQueue
Return type:

void