disasterdrop / silex-simple-bus-provider
Silex 提供程序,支持 SimpleBus/MessageBus 的 Command bus 和 Event bus 功能
v1.0
2017-09-01 07:41 UTC
Requires
- php: ^5.5 || ^7.0
- silex/silex: 2.*
- simple-bus/message-bus: 3.*
This package is not auto-updated.
Last update: 2024-09-23 06:57:15 UTC
README
由 Sebastian Hübner 编写
这是一个为 SimpleBus/MessageBus 的 Silex 提供程序,由 Matthias Noback 创建
使用此提供程序,您可以在 silex 应用程序中注册新的事件和 CommandHandlers。
事件总线
注册事件总线
$app->register(new \Disasterdrop\SimpleBusProvider\Provider\EventBusProvider());
向事件总线添加订阅者
// Event Bus
$app['eventSubscribers'] = function ($app) {
$subscribers = [
SomeEventHappens::class => [
function ($message) use ($app) {
$eventSubscriber = new SomeEventHappens($app['someService']);
return $eventSubscriber->notify($message);
}
]
];
return $subscribers;
};
命令处理器
注册命令处理器
$app->register(new Disasterdrop\SimpleBusProvider\Provider\CommandBusProvider());
向命令总线添加处理器
// Command Bus
$app['commandHandlers'] = function ($app) {
$handlers = [
SomeCommand::class => function ($command) use ($app) {
$commandHandler = new SomeCommandHandler($app['pollWriteRepository'], $app['eventBus']);
return $commandHandler->handle($command);
},
];
return $handlers;
};