An open API service indexing awesome lists of open source software.

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

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
```