Open jeckel opened 2 years ago
Documentation for obsolete CommandBus:
Warning, this package is still a Work in progress
Require: php >= 8.0
Install it via composer
composer require jeckel-lab/command-bus
The best way to start is by using the CommandBusBuilder
:
use JeckelLab\CommandBus\CommandBus\CommandBusBuilder;
/**
* @var Psr\ContainerInterface $container
*/
$build = new CommandBusBuilder($container);
Then you can register your command handlers. Each handler should implement the CommandHandler
interface.
// All command handler should implement the `CommandHandler` interface
$builder->addHandler(
FirstCommandHandler::class,
SecondCommandHandler::class
);
$builder->addHandler(
ThridCommandHandler::class
)
Then you can also add some decorators to the bus. Decorators should implement the CommandBusDecorator
interface, and it's suggest to extend directly the AbstractCommandBusDecorator
class.
$builder->addDecorator(new SimpleCommandBusDecorator());
Finally, just build the command bus:
$commandBus = $builder->build();
When command bus is correctly build, it's easy to use it:
/** @var CommandResponse $response */
$response = $commandBus->dispatch(new MyCommand());
Update readme on how to configure it, and how to use It with DI tools
With PHP/DI