512. Class

512.1. Zend\EventManager\SharedEventManager

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.

512.1.1. Methods

512.1.1.1. attach

attach()

Attach a listener to an event

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:

<code> $sharedEventManager = new SharedEventManager(); $sharedEventManager->attach(

array(‘MyResourceAbstractResource’, ‘MyResourceEntityResource’), ‘getAll’, function ($e) use ($cache) {

if (!$id = $e->getParam(‘id’, false)) {
return;

} if (!$data = $cache->load(get_class($resource) . ‘::getOne::’ . $id )) {

return;

} return $data;

}

); </code>

Parameters:
  • string|array – Identifier(s) for event emitting component(s)
  • string
  • callable – PHP Callback
  • int – Priority at which listener should execute
Return type:

CallbackHandler|array Either CallbackHandler or array of CallbackHandlers

512.1.1.2. attachAggregate

attachAggregate()

Attach a listener aggregate

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

Parameters:
  • SharedListenerAggregateInterface
  • int – If provided, a suggested priority for the aggregate to use
Return type:

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

512.1.1.3. detach

detach()

Detach a listener from an event offered by a given resource

Parameters:
  • string|int
  • CallbackHandler
Return type:

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

512.1.1.4. detachAggregate

detachAggregate()

Detach a listener aggregate

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

Parameters:SharedListenerAggregateInterface
Return type:mixed return value of {@link SharedListenerAggregateInterface::detachShared()}

512.1.1.5. getEvents

getEvents()

Retrieve all registered events for a given resource

Parameters:string|int
Return type:array

512.1.1.6. getListeners

getListeners()

Retrieve all listeners for a given identifier and event

Parameters:
  • string|int
  • string|int
Return type:

false|PriorityQueue

512.1.1.7. clearListeners

clearListeners()

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

Parameters:
  • string|int
  • null|string
Return type:

bool