awd-studio / command-bus
A command bus definition
Installs: 4
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/awd-studio/command-bus
Requires
Requires (Dev)
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2022-02-01 13:16:24 UTC
README
Provides a simple implementation of the Command bus pattern.
Install
composer require awd-studio/command-bus
Usage
- Implement a
\AwdStudio\CommandBus\Handler\HandlersCollection
(or use a defined one -\AwdStudio\CommandBus\Simple\ArrayCollection
) - Register there all off handlers (must implement
AwdStudio\CommandBus\Handler\CommandHandler
interface) - And then - you'll be able to use the bus (
AwdStudio\CommandBus\CommandBus
):
<?php use \AwdStudio\CommandBus\CommandBus; use \AwdStudio\CommandBus\Simple\ArrayCollection; // Creating the handlers collection $handlers = new ArrayCollection(); // Fill it with handlers $handlers->add(new MyCommandAHandler()); $handlers->add(new MyCommandBHandler()); // Remove handlers, if it's required $handlers->remove(new MyCommandCHandler()); // Creating the bus $bus = new CommandBus($handlers); // Handle commands $bus->handle(new MyCommandA()); $bus->handle(new MyCommandB());
Testing
To run tests - execute next script:
composer test # or with coverage composer coverage