bauhaus / message-bus
又一个消息总线实现
v0.0.0
2021-09-25 23:08 UTC
Requires
- php: ^8.0
- psr/container: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-17 07:12:10 UTC
README
消息总线
安装
$ composer require bauhaus/message-bus
入门
<?php use Bauhaus\MessageBus; use Bauhaus\MessageBusSettings; class YourCommand {} class YourCommandHandler { public function __invoke(CommandA $command): void {} } class YourQuery {} class YourQueryResult {} class YourQueryHandler { public function __invoke(YourQuery $query): YourQueryResult { return new YourQueryResult(); } } $messageBus = MessageBus::build( MessageBusSettings::new() ->withPsrContainer(/* Pass here your favorite PSR container */) ->withHandlers( YourCommandAHandler::class, YourQueryHandler::class, ); ); $result = $messageBus->dispatch(new YourCommand()); is_null($result); // true $result = $messageBus->dispatch(new YourCommand()); $result instanceof YourQueryResult; // true
贡献
提出问题: https://github.com/bauhausphp/message-bus/issues 代码: https://github.com/bauhausphp/contributor-tool