https://github.com/awd-studio/command-bus
A very simple implementation of the Command bus pattern on PHP
https://github.com/awd-studio/command-bus
command-bus
Last synced: 7 months ago
JSON representation
A very simple implementation of the Command bus pattern on PHP
- Host: GitHub
- URL: https://github.com/awd-studio/command-bus
- Owner: awd-studio
- Created: 2019-03-31T01:12:54.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-03-31T01:12:58.000Z (almost 7 years ago)
- Last Synced: 2025-03-23T07:33:21.281Z (12 months ago)
- Topics: command-bus
- Language: PHP
- Homepage: https://github.com/awd-studio/command-bus
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# AWD Command Bus
Provides a simple implementation of the Command bus pattern.
### Install
```bash
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
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:
```bash
composer test
# or with coverage
composer coverage
```