scripthoodie / cmdbus
A dead simple command bus for PHP
v1.0.1
2026-10-18 00:31 UTC
Requires
- php: ^8.4
- php-di/invoker: ^2.0
- psr/log: ^3.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.75
- phpstan/phpstan: ^2.1
- phpstan/phpstan-phpunit: ^2.0
- phpunit/phpunit: ^11.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A dead simple command bus for PHP
cmdbus dispatches commands to handlers. It's easy to use and bundled with features such as middlewares and handler locators.
Installation
Install the latest version with:
composer require scripthoodie/cmdbus
cmdbus requires PHP 8.4 or above.
Basic usage
<?php
use ScriptHoodie\CmdBus\Command;
use ScriptHoodie\CmdBus\CmdBus;
use ScriptHoodie\CmdBus\Middlewares\LogMiddleware;
$bus = new CmdBus();
$bus->addHandler('product.create', function (string $name, int $price) {
// ...your application logic
});
$bus->addMiddleware(new LogMiddleware($logger), 'product.*');
$productId = $bus->handle(new Command('product.create', [
'name' => 'Hoodie',
'price' => 42,
]));
// handle() returns whatever the handler returned
Documentation
The full documentation lives in the docs directory:
- Commands — building commands and naming rules
- Handlers — what can be a handler
- Handler locators — resolving handlers at dispatch time
- Middlewares — wrapping command handling
Submitting bugs and feature requests
Bugs and feature requests are tracked on Codeberg; see https://codeberg.org/scripthoodie/cmdbus/issues for the repository link.
Contributing
See CONTRIBUTING.md for the development environment.
License
cmdbus is licensed under the GPL-3.0-or-later License — see the LICENSE file for details.