Static version of 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.

package Default
inherited_from \Zend\EventManager\SharedEventManager

 Methods

Attach a listener to an event

attach(string|array $id, string $event, callable $callback, integer $priority = 1) : \Zend\Stdlib\CallbackHandler | array
Inherited

Allows attaching a callback to an event offered by one or more identifying components. As an example, the following connects to the "getAll" event of both an AbstractResource and EntityResource:

$sharedEventManager = new SharedEventManager(); $sharedEventManager->attach( array('My\Resource\AbstractResource', 'My\Resource\EntityResource'), 'getAll', function ($e) use ($cache) { if (!$id = $e->getParam('id', false)) { return; } if (!$data = $cache->load(get_class($resource) . '::getOne::' . $id )) { return; } return $data; } );

inherited_from \Zend\EventManager\SharedEventManagerInterface::attach()

Parameters

$id

stringarray

Identifier(s) for event emitting component(s)

$event

string

$callback

callable

PHP Callback

$priority

integer

Priority at which listener should execute

Returns

\Zend\Stdlib\CallbackHandlerarrayEither CallbackHandler or array of CallbackHandlers

Attach a listener aggregate

attachAggregate(\Zend\EventManager\SharedListenerAggregateInterface $aggregate, integer $priority = 1) : mixed
Inherited

Listener aggregates accept an EventManagerInterface instance, and call attachShared() one or more times, typically to attach to multiple events using local methods.

inherited_from \Zend\EventManager\SharedEventAggregateAwareInterface::attachAggregate()

Parameters

$aggregate

\Zend\EventManager\SharedListenerAggregateInterface

$priority

integer

If provided, a suggested priority for the aggregate to use

Returns

mixedreturn value of {@link ListenerAggregateInterface::attachShared()}

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

clearListeners(string|integer $id, null|string $event = null) : boolean
Inherited
inherited_from \Zend\EventManager\SharedEventManagerInterface::clearListeners()

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
Inherited
inherited_from \Zend\EventManager\SharedEventManagerInterface::detach()

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

Detach a listener aggregate

detachAggregate(\Zend\EventManager\SharedListenerAggregateInterface $aggregate) : mixed
Inherited

Listener aggregates accept a SharedEventManagerInterface instance, and call detachShared() of all previously attached listeners.

inherited_from \Zend\EventManager\SharedEventAggregateAwareInterface::detachAggregate()

Parameters

$aggregate

\Zend\EventManager\SharedListenerAggregateInterface

Returns

mixedreturn value of {@link SharedListenerAggregateInterface::detachShared()}

Retrieve all registered events for a given resource

getEvents(string|integer $id) : array
Inherited
inherited_from \Zend\EventManager\SharedEventManagerInterface::getEvents()

Parameters

$id

stringinteger

Returns

array

Retrieve instance

getInstance() : \Zend\EventManager\StaticEventManager
Static

Returns

\Zend\EventManager\StaticEventManager

Retrieve all listeners for a given identifier and event

getListeners(string|integer $id, string|integer $event) : false | \Zend\Stdlib\PriorityQueue
Inherited
inherited_from \Zend\EventManager\SharedEventManagerInterface::getListeners()

Parameters

$id

stringinteger

$event

stringinteger

Returns

false\Zend\Stdlib\PriorityQueue

Is a singleton instance defined?

hasInstance() : boolean
Static

Returns

boolean

Reset the singleton instance

resetInstance() : void
Static

Set the singleton to a specific SharedEventManagerInterface instance

setInstance(\Zend\EventManager\SharedEventManagerInterface $instance) : void
Static

Parameters

$instance

\Zend\EventManager\SharedEventManagerInterface

Singleton

__construct() 

Singleton

__clone() : void

 Properties

 

Identifiers with event connections

$identifiers : array

Default

array()
 

$instance

$instance : \Zend\EventManager\SharedEventManagerInterface

Default

Static