stratadox/command-handling

v0.2 2019-09-21 16:48 UTC

This package is auto-updated.

Last update: 2024-04-22 03:31:16 UTC


README

A simple command handling mechanism.

Build Status Coverage Status Scrutinizer Code Quality

Installation

Install using composer require stratadox/command-handling

Example

<?php
use Stratadox\CommandHandling\CommandBus;

$bus = CommandBus::handling([
    SomeCommand::class => new SomeHandler(),
    OtherCommand::class => new OtherHandler(),
]);
$bus->handle(new SomeCommand('foo'));

Glossary

Command

Commands are simple messages (DTO) that represent a request for an operation. These commands are not the same kind as described in the GOF design patterns, but rather command messages from the CQRS realm.

Handler

A command handler receives the commands, either accepting them and initiating the operation, or denying them and throwing an exception.

Bus

The command bus routes the input command to the appropriate handler.

Middleware

Middleware can be configured to perform operations before or after handling commands, or on exception cases.

Such middleware can be used to introduce automated logging of all requests, to automatically reject unauthorised access or to handle persistence concerns. Using the middleware functionality in this way grants the benefits of what people call aspect-oriented programming, without most of the downsides that come with.