Zend\EventManager\LazyEventListener extends from LazyListener, but requires supplying the event name to which to attach, and optionally the priority, in the definition supplied at construction. This allows it to be a standalone instance that a listener aggregate can then query and use to attach to an event manager instance.


As noted in the introduction, the LazyEventListener is aware of two additional keys in the definition supplied at instantiation:

As an example, let's assume:

Additionally, we'll assume that we have a container-interop instance in the variable $container and an event manager in the variable $events.

You could create the lazy event listener as follows:

use My\Application\Listener;
use Zend\EventManager\LazyEventListener;

$listener = new LazyEventListener([
    'listener' => Listener::class,
    'method'   => 'onDispatch',
    'event'    => 'dispatch',
    'priority' => 100,
], $container);


LazyEventListener exposes two methods:


The LazyEventListener features are primarily geared towards registering lazy listeners in aggregates. To that end, you will rarely instantiate or interact with them directly; instead, you'll leave that to the LazyListenerAggregate.