mmalessa / command-bus
Simple library to implement 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
Implementation of a simple command bus.
https://github.com/mmalessa/command-bus
Use it at your own risk.
Install
composer req mmalessa/command-bus
Example of use
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);