Zend\EventManager\SharedEventManager::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('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; } ); </code>
Signature
public function attach(string|array
$id,
[string
$event = 1,
[callable
$callback = 1,
[integer
$priority = 1]]] )
Parameters
$id
— object- Identifier(s) for event emitting component(s)
$event
— string$callback
— object- PHP Callback
$priority
— integer- Priority at which listener should execute
Returns
- CallbackHandler|array
- Either CallbackHandler or array of CallbackHandlers