Zend Framework  3.0
Public Member Functions | Protected Attributes | List of all members
SharedEventManager Class Reference

Shared/contextual EventManager. More...

Public Member Functions

 attach ($identifier, $event, callable $listener, $priority=1)
 Attach a listener to an event emitted by components with specific identifiers.
 
 detach (callable $listener, $identifier=null, $eventName=null, $force=false)
 
 
 getListeners (array $identifiers, $eventName)
 Retrieve all listeners for a given identifier and event.
 
 clearListeners ($identifier, $eventName=null)
 
 
- Public Member Functions inherited from SharedEventManagerInterface
 detach (callable $listener, $identifier=null, $eventName=null)
 Detach a shared listener.
 

Protected Attributes

 $identifiers = []
 

Detailed Description

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.

Member Function Documentation

attach (   $identifier,
  $event,
callable  $listener,
  $priority = 1 
)

Attach a listener to an event emitted by components with specific identifiers.

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

$sharedEventManager = new SharedEventManager(); foreach (['My', 'My'] as $identifier) { $sharedEventManager->attach( $identifier, 'getAll', function ($e) use ($cache) { if (!$id = $e->getParam('id', false)) { return; } if (!$data = $cache->load(get_class($resource) . '::getOne::' . $id )) { return; } return $data; } ); }

Parameters
string$identifierIdentifier for event emitting component.
string$event
callable$listenerListener that will handle the event.
int$priorityPriority at which listener should execute
Returns
void
Exceptions
Exception\InvalidArgumentExceptionfor invalid identifier arguments.
Exception\InvalidArgumentExceptionfor invalid event arguments.

Implements SharedEventManagerInterface.

clearListeners (   $identifier,
  $eventName = null 
)
detach ( callable  $listener,
  $identifier = null,
  $eventName = null,
  $force = false 
)

getListeners ( array  $identifiers,
  $eventName 
)

Retrieve all listeners for a given identifier and event.

Parameters
array$identifiers
string$eventName
Returns
array[]
Exceptions
Exception\InvalidArgumentException

Implements SharedEventManagerInterface.

Member Data Documentation

$identifiers = []
protected