2017 © Pedro Peláez
 

library command-bus

Command bus and executable commands with a return/response

image

ashleydawson/command-bus

Command bus and executable commands with a return/response

  • Monday, January 2, 2017
  • by AshleyDawson
  • Repository
  • 1 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Command Bus

Build Status, (*1)

Super-simple command bus implementation that allows return types. Each command has a single, designated handler., (*2)

Note: Depending on your architecture - it might not be appropriate for commands to return a response. Typically, in CQS architecture, state change is observed/measured via events or queries., (*3)

Installation

Install the command bus library via Composer:, (*4)

$ composer require ashleydawson/command-bus

Basic Usage

To use the command bus, start by adding a command:, (*5)

<?php

namespace Acme\Command;

class MyCommand
{
    public $something;
}

Then, define a command handler for the command, command handlers must implement the magic __invoke() method, type-hinted with the command to be handled:, (*6)

<?php

namespace Acme\Command;

class MyCommandHandler
{
    public function __invoke(MyCommand $command)
    {
        // Do something with the command here

        return 'Something useful';
    }
}

Then, put everything together (add command handler to command bus and execute command):, (*7)

<?php

require __DIR__.'/vendor/autoload.php';

use AshleyDawson\CommandBus\CommandBus;
use Acme\Command\MyCommand;
use Acme\Command\MyCommandHandler;

// Instantiate a command bus
$commandBus = new CommandBus();

// Add a handler to the bus
$commandBus->addHandler(new MyCommandHandler());

// Execute a command, "Something useful" will be echoed
echo $commandBus->execute(new MyCommand());

Tests

To run the test suite, execute the following:, (*8)

$ bin/phpunit

The Versions

02/01 2017

dev-master

9999999-dev

Command bus and executable commands with a return/response

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Ashley Dawson

domain command bus response ddd state return

02/01 2017

1.0.0

1.0.0.0

Command bus and executable commands with a return/response

  Sources   Download

MIT

The Requires

  • php >=5.5

 

The Development Requires

by Ashley Dawson

domain command bus response ddd state return