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.

category Zend
package Zend_EventManager

 Methods

Attach a listener to an event

attach(string | array $id, string $event, \Zend\EventManager\callable $callback, int $priority) : \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\SharedEventManager::attach()

Parameters

$id

stringarray

Identifier(s) for event emitting component(s)

$event

string

$callback

\Zend\EventManager\callable

PHP Callback

$priority

int

Priority at which listener should execute

Returns

\Zend\Stdlib\CallbackHandlerarrayEither CallbackHandler or array of CallbackHandlers

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

clearListeners(string | int $id, null | string $event) : bool
Inherited

inherited_from \Zend\EventManager\SharedEventManager::clearListeners()

Parameters

$id

stringint

$event

nullstring

Returns

bool

Detach a listener from an event offered by a given resource

detach(string | int $id, \Zend\Stdlib\CallbackHandler $listener) : bool
Inherited

inherited_from \Zend\EventManager\SharedEventManager::detach()

Parameters

$id

stringint

Returns

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

Retrieve all registered events for a given resource

getEvents(string | int $id) : array
Inherited

inherited_from \Zend\EventManager\SharedEventManager::getEvents()

Parameters

$id

stringint

Returns

array

Retrieve all listeners for a given identifier and event

getListeners(string | int $id, string | int $event) : false | \Zend\Stdlib\PriorityQueue
Inherited

inherited_from \Zend\EventManager\SharedEventManager::getListeners()

Parameters

$id

stringint

$event

stringint

Returns

Is a singleton instance defined?

hasInstance() : bool

Returns

bool

Reset the singleton instance

resetInstance() : void

Set the singleton to a specific SharedEventManagerInterface instance

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

Singleton

__construct() : void

Singleton

__clone() : void

 Properties

 

Identifiers with event connections

$identifiers : array
Inherited

inherited_from \Zend\EventManager\SharedEventManager::$$identifiers
 

$instance

$instance : \Zend\EventManager\StaticEventManager