mmalessa / command-bus
实现命令总线的一个简单库。
v1.2
2019-09-01 11:11 UTC
Requires
- php: >=7.2
This package is auto-updated.
Last update: 2024-09-29 05:28:44 UTC
README
简单命令总线的实现。
https://github.com/mmalessa/command-bus
使用风险自负。
安装
composer req mmalessa/command-bus
使用示例
class ExampleCommand { private $id; private $name; public function __construct(int $id, string $name) { $this->id = $id; $this->name = $name; } public function getId() { return $this->id; } public function getName() { return $this->name; } }
class ExampleCommandHandler { public function handle(ExampleCommand $command) { echo "Example command handler" . PHP_EOL; printf("ID: %s\n", $command->getId()); printf("Name: %s\n", $command->getName()); } }
use Mmalessa\CommandBus\CommandBus; $commandBus = new CommandBus(); $commandBus->subscribe(new ExampleCommandHandler()); // The command class is automatically detected based on the type of parameter // in the handler 'handle' method. $command = ExampleCommand::create(1, "Silifon"); $commandBus->handle($command);