LazyListenerAggregate
in package
implements
ListenerAggregateInterface
Uses
ListenerAggregateTrait
Aggregate listener for attaching lazy listeners.
Lazy listeners are listeners where creation is deferred until they are triggered; this removes the most costly mechanism of pulling a listener from a container unless the listener is actually invoked.
Usage is:
$events->attachAggregate(new LazyListenerAggregate(
$lazyEventListenersOrDefinitions,
$container
));
Interfaces, Classes, Traits and Enums
- ListenerAggregateInterface
- Interface for self-registering event listeners.
Table of Contents
- $listeners : array<string|int, callable>
- $container : ContainerInterface
- $env : array<string|int, mixed>
- $lazyListeners : array<string|int, LazyEventListener>
- Generated LazyEventListener instances.
- __construct() : mixed
- Constructor
- attach() : void
- Attach the aggregate to the event manager.
- detach() : mixed
- {@inheritDoc}
Properties
$listeners
protected
array<string|int, callable>
$listeners
= []
$container
private
ContainerInterface
$container
Container from which to pull lazy listeners.
$env
private
array<string|int, mixed>
$env
Additional environment/option variables to use when creating listener.
$lazyListeners
Generated LazyEventListener instances.
private
array<string|int, LazyEventListener>
$lazyListeners
= []
Methods
__construct()
Constructor
public
__construct(array<string|int, mixed> $listeners, ContainerInterface $container[, array<string|int, mixed> $env = [] ]) : mixed
Accepts the composed $listeners, as well as the $container and $env in order to create a listener aggregate that defers listener creation until the listener is triggered.
Listeners may be either LazyEventListener instances, or lazy event listener definitions that can be provided to a LazyEventListener constructor in order to create a new instance; in the latter case, the $container and $env will be passed at instantiation as well.
Parameters
- $listeners : array<string|int, mixed>
- $container : ContainerInterface
- $env : array<string|int, mixed> = []
Tags
Return values
mixed —attach()
Attach the aggregate to the event manager.
public
attach(EventManagerInterface $events[, mixed $priority = 1 ]) : void
Loops through all composed lazy listeners, and attaches them to the event manager.
Parameters
- $events : EventManagerInterface
- $priority : mixed = 1
Return values
void —detach()
{@inheritDoc}
public
detach(EventManagerInterface $events) : mixed
Parameters
- $events : EventManagerInterface