承接 meritum/bus-module 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-08

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固