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.

category Zend
package Zend_EventManager
copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
license New BSD License

 Methods

Attach a listener to an event

attach(string|array $id, string $event, callback $callback, integer $priority = 1) : void

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:

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; } );

Parameters

$id

stringarray

Identifier(s) for event emitting component(s)

$event

string

$callback

callback

PHP Callback

$priority

integer

Priority at which listener should execute

Clear all listeners for a given identifier, optionally for a specific event

clearListeners(string|integer $id, null|string $event = null) : boolean

Parameters

$id

stringinteger

$event

nullstring

Returns

boolean

Detach a listener from an event offered by a given resource

detach(string|integer $id, \Zend_Stdlib_CallbackHandler $listener) : boolean

Parameters

$id

stringinteger

$listener

\Zend_Stdlib_CallbackHandler

Returns

booleanReturns true if event and listener found, and unsubscribed; returns false if either event or listener not found

Retrieve all registered events for a given resource

getEvents(string|integer $id) : array

Parameters

$id

stringinteger

Returns

array

Retrieve all listeners for a given identifier and event

getListeners(string|integer $id, string|integer $event) : false | \Zend_Stdlib_PriorityQueue
inherited_from \Zend_EventManager_SharedEventCollection::getListeners()

Parameters

$id

stringinteger

$event

stringinteger

Returns

false\Zend_Stdlib_PriorityQueue

 Properties

 

Identifiers with event connections

$identifiers : array

Default

array()