maslosoft/signals
Composer 安装命令:
composer require maslosoft/signals
包简介
Wireless Cross-Component Communication
README 文档
README
Maslosoft Signals
Wireless Cross-Component Communication
Quick Install
composer require maslosoft/signals
Documentation
Connecting components
Various application components must be connected to each other. This should be made in a soft manner, so that when adding or removing component code will not require to change.
Wireless connection
Signals provide somthing like wireless connection between components. On of them emit signal, the other receives it. This can be done other way around. That one application component sends signal, and several components listen to that signal.
Wireless cross-component communication
This component allows for interaction of application components, without prior or explicit assignment.
Setup
Use composer to install
composer require maslosoft/signals:"*"
Or by hard way, download somewhere in your project and ensure autoloading works for Maslosoft\Signals\* and you include dep too;
Setup signals. After calling init any further instance will be configured same as below $signal.
$signal = new Maslosoft\Signals\Signal(); $signal->runtimePath = RUNTIME_PATH; $signal->paths = [ MODELS_PATH ]; $signal->init();
Generate signals definition, only once, hook it to your build script etc.
$signal = new Maslosoft\Signals\Signal(); (new Maslosoft\Signals\Utility($signal))->generate();
Usage
Emiting signal
Define signal:
namespace MyNamespace\Signals; class AccountMenuItems extends AdminMenuItems { public $item = []; }
Define class with slot with @SlotFor annotation
namespace Maslosoft\Ilmatar\Modules; class MyModule { /** * @SlotFor(MyNamespace\Signals\AccountMenuItems) */ public function reactOnAccountMenu(MyNamespace\Signals\AccountMenuItems $signal) { $signal->item = [ 'url' => '/content/myBlog', 'label' => 'My blog' ]; } }
Emit signal and get results of this call:
$signal = new Maslosoft\Signals\Signal(); $result = $signal->emit(new AdminMenuItems()); echo $result[0]->item[0]['label']; // My blog
Gathering signals
统计信息
- 总下载量: 6.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 0
- 依赖项目数: 9
- 推荐数: 1
其他信息
- 授权协议: AGPL-3.0-only
- 更新时间: 2013-12-05