0x13a/buxus

A framework-agnostic, minimal & lightweight PHP command bus

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

README

Build Status

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 https://medium.com/@0x13a/building-a-php-command-bus-a65e6ae6a6ac

Prerequisites

  • PHP >= 7.x
  • Composer

Install

composer require 0x13a/buxus

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