refinery29 / league-lazy-event
Provides a LazyListener for use with league/event which allows for lazy fetching of actual listeners.
This package's canonical repository appears to be gone and the package has been frozen as a result.
Installs: 23 309
Dependents: 0
Suggesters: 0
Security: 0
Stars: 14
Watchers: 41
Forks: 1
Open Issues: 0
Requires
- php: ^5.5 || ^7.0
- league/event: ^2.1.2
- psr/container: ^1.0.0
Requires (Dev)
- codeclimate/php-test-reporter: 0.4.4
- phpunit/phpunit: ^4.8.35
- refinery29/php-cs-fixer-config: 0.6.7
This package is not auto-updated.
Last update: 2024-06-08 17:18:33 UTC
README
This repository provides a LazyListener
for use with league/event
, which
allows for lazy fetching of an actual listener from the composed container.
Installation
Run
$ composer require refinery29/league-lazy-event
Usage
Register your actual listener as a service with the container:
use League\Container; $container = new Container(); $container->share(ExpensiveListener::class, function () { /* * here, some heavy lifting occurs that creates the actual listener, * which should implement the ListenerInterface */ return $listener; });
Then register a LazyListener
, composing the alias and the container:
use League\Event\Emitter; use Refinery29\Event\LazyListener; $emitter->addListener(ContentChangedEvent::class, LazyListener::fromAlias( ExpensiveListener::class, $container ));
Trigger your events as needed!
$emitter->emit(ContentChangedEvent::class, new ContentChangedEvent( $url, new DateTimeImmutable() );
👍 Listeners are only ever fetched from the container when the event is handled.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CONDUCT.md
.
License
This package is licensed using the MIT License.