PHPackages                             open-solid/bus - 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. [API Development](/categories/api)
4. /
5. open-solid/bus

ActiveLibrary[API Development](/categories/api)

open-solid/bus
==============

Simple Bus Component

v1.1.4(1y ago)316.2k↑160.3%3MITPHPPHP &gt;=8.2

Since Apr 17Pushed 1y ago1 watchersCompare

[ Source](https://github.com/open-solid/bus)[ Packagist](https://packagist.org/packages/open-solid/bus)[ RSS](/packages/open-solid-bus/feed)WikiDiscussions main Synced 2d ago

READMEChangelog (10)Dependencies (8)Versions (16)Used By (3)

Message Bus Component
=====================

[](#message-bus-component)

A message bus component is essential in modern applications for managing communication between different parts of the system. It acts as a central hub that routes messages between services, ensuring decoupled and scalable architecture. This allows individual components to interact without needing to know the specifics of each other, simplifying development and maintenance.

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

[](#installation)

```
composer require open-solid/bus
```

Usage
-----

[](#usage)

### Dispatching Message with the Bus

[](#dispatching-message-with-the-bus)

Think of the "bus" as a mail delivery system for your messages. It follows a specific path, decided by some rules (middleware), to send your message and handle it.

Here's a snippet on how to set it up and dispatch a message:

```
use App\Message\MyMessage;
use OpenSolid\Bus\Handler\MessageHandlersLocator;
use OpenSolid\Bus\Middleware\HandlingMiddleware;
use OpenSolid\Bus\NativeMessageBus;

// This is your custom function that does something when a message arrives.
$handler = function (MyMessage $message): mixed {
    // Do stuff with the message here...
};

// Setting up the bus with a middleware that knows who handles the message.
$bus = new NativeMessageBus([
    new HandlingMiddleware(new MessageHandlersLocator([
        MyMessage::class => [$handler], // Maps messages to handlers.
    ])),
]);

// Send a message using the bus.
$bus->dispatch(new MyMessage());
```

### Handling Messages

[](#handling-messages)

A "message handler" is what does the work when a message arrives. It can be a simple function or a method in a class. Here's how you set one up:

```
use App\Message\MyMessage;

class MyMessageHandler
{
    public function __invoke(MyMessage $message): mixed
    {
        // Process the message here...
    }
}
```

### Middleware

[](#middleware)

Middleware are helpers that perform tasks before and after your message is handled. They operate at the bus level, meaning they handle all messages dispatched through the message bus they are linked to.

Here's how to create one:

```
use OpenSolid\Bus\Envelope\Envelope;
use OpenSolid\Bus\Middleware\Middleware;
use OpenSolid\Bus\Middleware\NextMiddleware;

class MyMiddleware implements Middleware
{
    public function handle(Envelope $envelope, NextMiddleware $next): void
    {
        // Do something before the message handler works.

        $next->handle($envelope); // Call the next middleware

        // Do something after the message handler is done.
    }
}
```

### Decorators

[](#decorators)

Decorators are helpers that perform tasks before and after your message is handled. Unlike Middleware, decorators operate at the handler level, allowing you to modify or enhance specific handlers without changing their actual code.

Check this out in [decorator](https://github.com/yceruto/decorator) and [decorator-bundle](https://github.com/yceruto/decorator-bundle) packages.

Framework Integration
---------------------

[](#framework-integration)

- [cqs-bundle](https://github.com/open-solid/cqs-bundle) - Symfony bundle for Command-Query buses.
- [domain-event-bundle](https://github.com/open-solid/domain-event-bundle) - Symfony bundle for Event bus.

License
-------

[](#license)

This tool is available under the [MIT License](LICENSE), which means you can use it pretty freely in your projects.

###  Health Score

39

—

LowBetter than 84% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity62

Established project with proven stability

 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 ~17 days

Recently: every ~28 days

Total

15

Last Release

567d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/ebf906be9b4bb0c2060846ce9bbfe246df4e32bb5a8741ce1971ee923db2f8ae?d=identicon)[yceruto](/maintainers/yceruto)

---

Top Contributors

[![yceruto](https://avatars.githubusercontent.com/u/2028198?v=4)](https://github.com/yceruto "yceruto (66 commits)")

---

Tags

cqsmessage-busmessengerphp

###  Code Quality

TestsPHPUnit

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/open-solid-bus/health.svg)

```
[![Health](https://phpackages.com/badges/open-solid-bus/health.svg)](https://phpackages.com/packages/open-solid-bus)
```

###  Alternatives

[symfony/symfony

The Symfony PHP framework

31.4k87.2M2.2k](/packages/symfony-symfony)[symfony/dependency-injection

Allows you to standardize and centralize the way objects are constructed in your application

4.2k455.6M9.6k](/packages/symfony-dependency-injection)[symfony/cache

Provides extended PSR-6, PSR-16 (and tags) implementations

4.2k373.5M3.3k](/packages/symfony-cache)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6942.5M421](/packages/drupal-core-recommended)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

751291.4k43](/packages/civicrm-civicrm-core)[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.5k5.9M737](/packages/sylius-sylius)

PHPackages © 2026

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