EventManager/SharedEventManager.php
Zend Framework
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-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_EventManager
\Zend_EventManager_SharedEventManager
Package: Zend_EventManager




Shared/contextual EventManager
Allows attaching to EMs composed by other classes without having an instance first.
The assumption is that the SharedEventManager will be injected into EventManager
instances, and then queried for additional listeners when triggering an event.
- Implements
- Children
- \Zend_EventManager_StaticEventManager
- Category
- Zend
- Copyright
- Copyright (c) 2005-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Properties
Methods


attach(string | array $id, string $event, callback $callback, int $priority = 1) : void
Attach a listener to an event
Allows attaching a callback to an event offerred by one or more
identifying components. As an example, the following connects to the
"getAll" event of both an AbstractResource and EntityResource:
Parameters
SharedEventManager::getInstance()->connect(
array('My\Resource\AbstractResource', 'My\Resource\EntityResource'),
'getOne',
function ($e) use ($cache) {
if (!$id = $e->getParam('id', false)) {
return;
}
if (!$data = $cache->load(get_class($resource) . '::getOne::' . $id )) {
return;
}
return $data;
}
);
Name | Type | Description |
---|---|---|
$id | string | array | Identifier(s) for event emitting component(s) |
$event | string | |
$callback | callback | PHP Callback |
$priority | int | Priority at which listener should execute |


clearListeners(string | int $id, null | string $event = null) : bool
Clear all listeners for a given identifier, optionally for a specific event
Parameters
Returns
Name | Type | Description |
---|---|---|
$id | string | int | |
$event | null | string |
Type | Description |
---|---|
bool |


detach(string | int $id, \Zend_Stdlib_CallbackHandler $listener) : bool
Detach a listener from an event offered by a given resource
Parameters
Returns
Name | Type | Description |
---|---|---|
$id | string | int | |
$listener | \Zend_Stdlib_CallbackHandler |
Type | Description |
---|---|
bool | Returns true if event and listener found, and unsubscribed; returns false if either event or listener not found |


getEvents(string | int $id) : array
Retrieve all registered events for a given resource
Parameters
Returns
Name | Type | Description |
---|---|---|
$id | string | int |
Type | Description |
---|---|
array |


getListeners(string | int $id, string | int $event) : false | \Zend_Stdlib_PriorityQueue
Retrieve all listeners for a given identifier and event
Parameters
Returns
Name | Type | Description |
---|---|---|
$id | string | int | |
$event | string | int |
Type | Description |
---|---|
false | \Zend_Stdlib_PriorityQueue |