refinery29/league-lazy-event
最新稳定版本:0.3.0
Composer 安装命令:
composer require refinery29/league-lazy-event
包简介
Provides a LazyListener for use with league/event which allows for lazy fetching of actual listeners.
README 文档
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.
统计信息
- 总下载量: 23.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 15
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-09-14