Download the PHP package buonaparte/bnp-lazy-listener without Composer
On this page you can find all versions of the php package buonaparte/bnp-lazy-listener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download buonaparte/bnp-lazy-listener
More information about buonaparte/bnp-lazy-listener
Files in buonaparte/bnp-lazy-listener
Package bnp-lazy-listener
Short Description This library allows you to attach Lazy Listeners to a ZF2 EventManager
License BSD-3-Clause
Informations about the package bnp-lazy-listener
BnpLazyListener
This library allows you to attach Lazy Listeners to a ZF2 EventManager.
Installation
Setup
-
Add this project to your composer.json:
- Now tell composer to download BnpServiceDefinition by running the command:
!!! Notice this is not a Module, so you do not have to enable it in a ZF2 Application, moreover, you can use it
with the EventManager
decoupled component.
LazyListenerAggregate
There are many cases when instantiating a listener aggregate may be too expensive, especially when that listener will
be never triggered, LazyListenerAggregate
makes it possible to define a factory for your real listener, as well as
specifications for which events the future listener is subscribed, LazyListenerAggregate
will then instantiate your
listener when the first of subscribed is being triggered.
Now you can attach this PPO to the EventManager
:
We've used \Closure
here as factory, LazyListenerAggregate
however, accepts any valid callable
. As you can already
see this does not bring much flexibility, as we wrap statically all our listener dependencies, here is where the second
utility listener comes in handy.
ServicesListenerAggregateCollection
This is a ServiceLocatorAware
service that is able to aggregate a collection of other ListenerAggregate
s, from which,
the most important one is that described above.
All atom listeners are called delegates and can be represented as:
callable
- a callable to invoke to instantiate the delegate, optionally aServiceLocatorInterface
is passed as the only argumentstring
(a valid FQ class name implementingZend\EventManager\ListenerAggregateInterface
)string
(a valid FQ class name implementingZend\ServiceManager\FactoryInterface
)Zend\ServiceManager\FactoryInterface
instancestring
- not matching a factory class name - will makeServicesListenerAggregateCollection
to pull the delegate as a service from currently injected locatorarray
- containing 2 elements, the first one - any of above, to use as a lazy factory for theLazyListenerAggregate
and the second - an array defining the events being listened to, the second constructor argument for theLazyListenerAggregate
We can now define a bunch of listeners at a time using only a configuration array:
All versions of bnp-lazy-listener with dependencies
zendframework/zend-servicemanager Version 2.*
zendframework/zend-eventmanager Version 2.*