meritum/bus-module
Composer 安装命令:
composer require meritum/bus-module
包简介
Meritum module for bootstrapping georgeff/bus into the kernel ecosystem
README 文档
README
Meritum module for bootstrapping georgeff/bus into the kernel ecosystem.
Installation
composer require meritum/bus-module
Usage
Register the module with your kernel before boot:
use Meritum\BusModule\BusModule; $kernel->addModule(new BusModule());
The module registers HandlerLocatorInterface, HandlerResolverInterface, and DispatcherInterface. Resolve the dispatcher from the container to dispatch commands:
use Georgeff\Bus\DispatcherInterface; $dispatcher = $container->get(DispatcherInterface::class); $dispatcher->dispatch(new PlaceOrderCommand($data));
Handler convention
BusModule wires ClassNameLocator as the handler locator. Handler classes must be named after their command with a Handler suffix and must be invokable:
final class PlaceOrderCommandHandler { public function __invoke(PlaceOrderCommand $command): void { // ... } }
Handlers are resolved from the container, so register each handler as a service:
$kernel->define(PlaceOrderCommandHandler::class, fn() => new PlaceOrderCommandHandler());
Middleware
Tag services with bus.middleware to add them to the dispatch pipeline:
$kernel->define( LoggingMiddleware::class, fn(ContainerInterface $c) => new LoggingMiddleware($c->get(LoggerInterface::class)), )->tag('bus.middleware');
Middleware receive the command and a $next callable. Call $next($command) to continue the pipeline:
final class LoggingMiddleware { public function __invoke(object $command, callable $next): mixed { $this->logger->info('Dispatching', ['command' => $command::class]); $result = $next($command); $this->logger->info('Dispatched', ['command' => $command::class]); return $result; } }
Middleware runs in the order services are tagged.
Options
To bypass the middleware pipeline and use the plain dispatcher:
$kernel->addModule(new BusModule(useMiddlewareAwareDispatcher: false));
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-08