robotusers / commander
Command Bus abstraction for PHP.
Installs: 92 065
Dependents: 1
Suggesters: 1
Security: 0
Stars: 2
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1|^8
Requires (Dev)
- league/tactician: *
- phpstan/extension-installer: ^1.1
- phpstan/phpstan: ^0.12
- phpstan/phpstan-deprecation-rules: ^0.12.6
- phpunit/phpunit: ^7|^8
- prooph/service-bus: *
- simple-bus/message-bus: *
- squizlabs/php_codesniffer: ^3.0
Suggests
- league/tactician: To use TacticianAdapter.
- prooph/service-bus: To use ServiceBusAdapter.
- simple-bus/message-bus: To use SimpleBusAdapter.
This package is auto-updated.
Last update: 2024-10-23 18:36:55 UTC
README
Command Bus abstraction for PHP.
Installation
composer require robotusers/commander
Command Bus abstraction
This library provides a CommandBusInterface
which a command bus should implement.
Using the command bus
use Robotusers\Commander\CommandBusAwareInterface; use Robotusers\Commander\CommandBusAwareTrait; class OrdersController implements CommandBusAwareInterface { use CommandBusAwareTrait; public function makeOrder() { ... $command = new MakeOrderCommand($data); $this->handleCommand($command); ... } }
Adapters
The library provides adapters for the most common command bus implementations.
Tactician
composer require league/tactician
use League\Tactician\CommandBus; use Robotusers\Commander\Adapter\TacticianAdapter; $commandBus = new CommandBus($middleware); $adapter = new TacticianAdapter($commandBus); $controller->setCommandBus($adapter);
SimpleBus/MessageBus
composer require simple-bus/message-bus
use Robotusers\Commander\Adapter\SimpleBusAdapter; use SimpleBus\Message\Bus\Middleware\MessageBusSupportingMiddleware; $commandBus = new MessageBusSupportingMiddleware(); $adapter = new SimpleBusAdapter($commandBus); $controller->setCommandBus($adapter);
PSB - ProophServiceBus
composer require prooph/service-bus
use Prooph\ServiceBus\CommandBus; use Robotusers\Commander\Adapter\ServiceBusAdapter; $commandBus = new CommandBus(); $adapter = new ServiceBusAdapter($commandBus); $controller->setCommandBus($adapter);
Writing a custom adapter
You can write your custom adapter. The adapter must implement Robotusers\Commander\CommandBusInterface
.
class MyAdapter implements CommandBusInterface { public function handle($command) { //handle a command } }