Shared/contextual EventManager.
More...
|
| 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) |
|
|
|
| detach (callable $listener, $identifier=null, $eventName=null) |
| Detach a shared listener.
|
|
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.
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 | $identifier | Identifier for event emitting component. |
string | $event | |
callable | $listener | Listener that will handle the event. |
int | $priority | Priority at which listener should execute |
- Returns
- void
- Exceptions
-
Exception\InvalidArgumentException | for invalid identifier arguments. |
Exception\InvalidArgumentException | for 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.