0x13a/buxus

A framework-agnostic, minimal & lightweight PHP command bus

v0.3 2016-12-31 15:21 UTC

README

Build Status License Coverage Status composer.lock

Why a PHP Command Bus

  • Keeps Application logic separated from Domain logic
  • Commands enforce discoverability
  • Command Handlers enforce Single Responsibility Principle
  • Can be easily extended (decorated)

Read more here Building a PHP Command Bus

Prerequisites

Install

Install using composer

composer require 0x13a/buxus

Run test suite

vendor/bin/phpunit

Check code style

composer check-cs

Check Object Calisthenics rules

composer check-calisthenics

Getting started

You can simply define your Command => CommandHandler map and then instantiate your command bus, ready to use.

<?php

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

$commandHandlerMap = [
    CreateProductCommand::class => new CreateProductHandler()
];

$standardCommandBus = new \Buxus\Bus\StandardCommandBus(
    new \Buxus\Handler\StandardCommandHandlerLocator(
        new \Buxus\Map\InMemoryCommandHandlerMap($commandHandlerMap)
    )
);

$loggedCommandBus->dispatch(new CreateProductCommand('beer'));

Extending Command Bus

If you want to extend the default Command Bus functionality, you can decorate it, creating a new one based on your needs.

See Decorator Pattern

<?php

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

$commandHandlerMap = [
    CreateProductCommand::class => new CreateProductHandler()
];

$standardCommandBus = new \Buxus\Bus\StandardCommandBus(
    new \Buxus\Handler\StandardCommandHandlerLocator(
        new \Buxus\Map\InMemoryCommandHandlerMap($commandHandlerMap)
    )
);

$loggedCommandBus = new LoggedCommandBus(
    $standardCommandBus,
    new Logger()
);

$loggedCommandBus->dispatch(new CreateProductCommand('beer'));

In this project

License

Buxus is licensed under the MIT license. See License File for more information