EventManager/EventManager.php
LICENSE
This source file is subject to the new BSD license that is bundled with this package in the file LICENSE.txt. It is also available through the world-wide-web at this URL: http://framework.zend.com/license/new-bsd If you did not receive a copy of the license and are unable to obtain it through the world-wide-web, please send an email to license@zend.com so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_EventManager
\Zend_EventManager_EventManager
Use the EventManager when you want to create a per-instance notification system for your objects.
- Implements
- \Zend_EventManager_EventCollection
- \Zend_EventManager_SharedEventCollectionAware
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties

string $eventClass = 'Zend_EventManager_Event'Class representing the event being emitted
'Zend_EventManager_Event'Details- Type
- string

array $identifiers = array()array()Details- Type
- array
Methods

__construct(null | string | int | array | \Traversable $identifiers = null) : voidConstructor
Allows optionally specifying identifier(s) to use to pull signals from a StaticEventManager.
| Name | Type | Description |
|---|---|---|
| $identifiers | null | string | int | array | \Traversable |

addIdentifiers(string | int | array | \Traversable $identifiers) : \Zend_EventManager_EventManagerAdd some identifier(s) (appends to any currently set identifiers)
| Name | Type | Description |
|---|---|---|
| $identifiers | string | int | array | \Traversable |
| Type | Description |
|---|---|
| \Zend_EventManager_EventManager |

attach(string | array | \Zend_EventManager_ListenerAggregate $event, callback | int $callback = null, int $priority = 1) : \Zend_Stdlib_CallbackHandler | mixedAttach 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.
| Name | Type | Description |
|---|---|---|
| $event | string | array | \Zend_EventManager_ListenerAggregate | An event or array of event names. If a ListenerAggregate, proxies to {@link attachAggregate()}. |
| $callback | callback | int | If string $event provided, expects PHP callback; for a ListenerAggregate $event, this will be the priority |
| $priority | int | If provided, the priority at which to register the callback |
| Type | Description |
|---|---|
| \Zend_Stdlib_CallbackHandler | mixed | CallbackHandler if attaching callback (to allow later unsubscribe); mixed if attaching aggregate |

attachAggregate(\Zend_EventManager_ListenerAggregate $aggregate, int $priority = 1) : mixedAttach 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.
| Name | Type | Description |
|---|---|---|
| $aggregate | \Zend_EventManager_ListenerAggregate | |
| $priority | int | If provided, a suggested priority for the aggregate to use |
| Type | Description |
|---|---|
| mixed | return value of {@link Zend_EventManager_ListenerAggregate::attach()} |

clearListeners(string $event) : voidClear all listeners for a given event
| Name | Type | Description |
|---|---|---|
| $event | string |

detach(\Zend_Stdlib_CallbackHandler | \Zend_EventManager_ListenerAggregate $listener) : boolUnsubscribe a listener from an event
| Name | Type | Description |
|---|---|---|
| $listener | \Zend_Stdlib_CallbackHandler | \Zend_EventManager_ListenerAggregate |
| Type | Description |
|---|---|
| bool | Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found |
| Exception | Description |
|---|---|
| \Zend_EventManager_Exception_InvalidArgumentException | if invalid listener provided |

detachAggregate(\Zend_EventManager_ListenerAggregate $aggregate) : mixedDetach a listener aggregate
Listener aggregates accept an EventCollection instance, and call detach() of all previously attached listeners.
| Name | Type | Description |
|---|---|---|
| $aggregate | \Zend_EventManager_ListenerAggregate |
| Type | Description |
|---|---|
| mixed | return value of {@link Zend_EventManager_ListenerAggregate::detach()} |

getIdentifiers() : arrayGet the identifier(s) for this Zend_EventManager_EventManager
| Type | Description |
|---|---|
| array |

getListeners(string $event) : \Zend_Stdlib_PriorityQueueRetrieve all listeners for a given event
| Name | Type | Description |
|---|---|---|
| $event | string |
| Type | Description |
|---|---|
| \Zend_Stdlib_PriorityQueue |

getSharedCollections() : false | \Zend_EventManager_SharedEventCollectionGet static collections container
| Type | Description |
|---|---|
| false | \Zend_EventManager_SharedEventCollection |

getSharedListeners(string $event) : arrayGet list of all listeners attached to the shared collection for identifiers registered by this instance
| Name | Type | Description |
|---|---|---|
| $event | string |
| Type | Description |
|---|---|
| array |

insertListeners(\Zend_Stdlib_PriorityQueue $masterListeners, \Zend_Stdlib_PriorityQueue $listeners) : voidAdd listeners to the master queue of listeners
Used to inject shared listeners and wildcard listeners.
| Name | Type | Description |
|---|---|---|
| $masterListeners | \Zend_Stdlib_PriorityQueue | |
| $listeners | \Zend_Stdlib_PriorityQueue |

prepareArgs(array $args) : \ArrayObjectPrepare 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().
| Name | Type | Description |
|---|---|---|
| $args | array |
| Type | Description |
|---|---|
| \ArrayObject |

setEventClass(string $class) : \Zend_EventManager_EventManagerSet the event class to utilize
| Name | Type | Description |
|---|---|---|
| $class | string |
| Type | Description |
|---|---|
| \Zend_EventManager_EventManager |

setIdentifiers(string | int | array | \Traversable $identifiers) : \Zend_EventManager_EventManagerSet the identifiers (overrides any currently set identifiers)
| Name | Type | Description |
|---|---|---|
| $identifiers | string | int | array | \Traversable |
| Type | Description |
|---|---|
| \Zend_EventManager_EventManager |

setSharedCollections(\Zend_EventManager_StaticEventCollection $collections) : voidSet static collections container
| Name | Type | Description |
|---|---|---|
| $collections | \Zend_EventManager_StaticEventCollection |

trigger(string $event, string | object $target = null, array | \ArrayAccess $argv = array(), null | callback $callback = null) : \Zend_EventManager_ResponseCollectionTrigger all listeners for a given event
Can emulate triggerUntil() if the last argument provided is a callback.
| Name | Type | Description |
|---|---|---|
| $event | string | |
| $target | string | object | Object calling emit, or symbol describing target (such as static method name) |
| $argv | array | \ArrayAccess | Array of arguments; typically, should be associative |
| $callback | null | callback |
| Type | Description |
|---|---|
| \Zend_EventManager_ResponseCollection | All listener return values |

triggerListeners(string $event, \EventDescription $e, null | callback $callback = null) : \ResponseCollectionTrigger listeners
Actual functionality for triggering listeners, to which both trigger() and triggerUntil() delegate.
| Name | Type | Description |
|---|---|---|
| $event | string | Event name |
| $e | \EventDescription | |
| $callback | null | callback |
| Type | Description |
|---|---|
| \ResponseCollection |

triggerUntil(string $event, string | object $target, array | \ArrayAccess $argv = null, Callable $callback = null) : \Zend_EventManager_ResponseCollectionTrigger 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.
| Name | Type | Description |
|---|---|---|
| $event | string | |
| $target | string | object | Object calling emit, or symbol describing target (such as static method name) |
| $argv | array | \ArrayAccess | Array of arguments; typically, should be associative |
| $callback | Callable |
| Type | Description |
|---|---|
| \Zend_EventManager_ResponseCollection |
| Exception | Description |
|---|---|
| \Zend_Stdlib_Exception_InvalidCallbackException | if invalid callback provided |

unsetSharedCollections() : voidRemove any shared collections
Sets $sharedCollections to boolean false to disable ability to lazy-load static event manager instance.