PHPackages                             austinhyde/minibus - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [CLI &amp; Console](/categories/cli)
4. /
5. austinhyde/minibus

ActiveLibrary[CLI &amp; Console](/categories/cli)

austinhyde/minibus
==================

A lightweight command bus implementation

v0.1.1(10y ago)2231MITPHPPHP &gt;=5.4.0

Since Dec 27Pushed 10y ago1 watchersCompare

[ Source](https://github.com/austinhyde/minibus)[ Packagist](https://packagist.org/packages/austinhyde/minibus)[ RSS](/packages/austinhyde-minibus/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

Minibus - A tiny Command Bus
============================

[](#minibus---a-tiny-command-bus)

Minibus helps separate your interface from your implementation - like your REST handlers from your database calls.

It was inspired by [Grafana's command bus](https://github.com/grafana/grafana/blob/master/pkg/bus/bus.go) and the [Tactician](http://tactician.thephpleague.com/) command bus library.

Why do I need this?
-------------------

[](#why-do-i-need-this)

What a command bus allows is the decoupling of *what* needs done from *how* it gets done. As systems get more complex, keeping the interface separate from the implementation like this improves maintainability.

Ross Tuck gave an [exemplary talk](https://www.youtube.com/watch?v=ajhqScWECMo) outlining service layers and command busses - I recommend you watch this if you think you need a command bus.

Installation
------------

[](#installation)

Via composer: `composer require austinhyde/minibus`

Usage
=====

[](#usage)

Minibus provides an extremely simple command bus implementation out of the box: `Minibus\Bus`.

This gives you everything you need to begin dispatching commands and publishing events:

```
$bus = new Minibus\Bus;

$bus->addHandler(function(NewUserCommand $cmd) use ($db, $bus) {
  $row = $db->query("INSERT INTO users (username, email) VALUES (?, ?) RETURNING *",
    [$cmd->username, $cmd->email]);
  $user = User::fromRow($row);
  $bus->publish(new UserAddedEvent($user));
  return $user;
});

$bus->addListener(function(UserAddedEvent $event) use ($log) {
  $log->info("Added user: " . $event->getUser()->getUsername());
});

$router->get(function($req, $res) use ($bus) {
  $cmd = new NewUserCommand($req->body->username, $req->body->email);
  $user = $bus->dispatch($cmd);
  return $user->toJson();
});
```

`addHandler` and `addListener` take any callable as their first argument, and automatically infer the type of command or event they'll be registered for by reflecting the type hint of the first parameter. If you want to override the "type" of the command or event (not necessarily a class name), you can specify a type as the second parameter.

`dispatch` and `publish` will accept any value as a command or event, although if they're an object, Minibus will use the class name to automatically find the correct command handler or event listeners. Again, you can override the "type" by passing it as the second parameter.

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~5 days

Total

2

Last Release

3826d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2c221166d547b835ed6aa280ffc6a4397686c787257bc01652a474202ccc7c9c?d=identicon)[austinhyde](/maintainers/austinhyde)

---

Top Contributors

[![austinhyde](https://avatars.githubusercontent.com/u/694995?v=4)](https://github.com/austinhyde "austinhyde (8 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/austinhyde-minibus/health.svg)

```
[![Health](https://phpackages.com/badges/austinhyde-minibus/health.svg)](https://phpackages.com/packages/austinhyde-minibus)
```

###  Alternatives

[seld/cli-prompt

Allows you to prompt for user input on the command line, and optionally hide the characters they type

24726.4M22](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

13045.3M6.2k](/packages/illuminate-console)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
