awd-studio/command-bus

This package is abandoned and no longer maintained. The author suggests using the awd-studio/service-buses package instead.

A command bus definition

dev-master 2019-03-31 01:11 UTC

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