stratadox / command-handling
Requires
- php: >=7.2
Requires (Dev)
- php-coveralls/php-coveralls: ^2.1
- phpstan/phpstan: ^0.11.1
- phpunit/phpunit: ^8.0
- roave/security-advisories: dev-master
This package is auto-updated.
Last update: 2024-10-22 04:31:37 UTC
README
A simple command handling mechanism.
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.