PHPackages                             georgeff/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. [Utility &amp; Helpers](/categories/utility)
4. /
5. georgeff/bus

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

georgeff/bus
============

A message bus library

1.0.0(3mo ago)0321MITPHPPHP ^8.2CI passing

Since Feb 12Pushed 3w agoCompare

[ Source](https://github.com/MikeGeorgeff/bus)[ Packagist](https://packagist.org/packages/georgeff/bus)[ RSS](/packages/georgeff-bus/feed)WikiDiscussions main Synced 1w ago

READMEChangelogDependencies (4)Versions (2)Used By (1)

Bus
===

[](#bus)

A command bus library for PHP 8.2+.

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

[](#installation)

```
composer require georgeff/bus
```

Usage
-----

[](#usage)

### Defining Commands and Handlers

[](#defining-commands-and-handlers)

A command is any plain object. A handler is a callable — typically a class with an `__invoke` method.

```
class SendEmail
{
    public function __construct(
        public readonly string $to,
        public readonly string $subject,
        public readonly string $body,
    ) {}
}

class SendEmailHandler
{
    public function __invoke(SendEmail $command): void
    {
        // send the email
    }
}
```

### Dispatching Commands

[](#dispatching-commands)

The `Dispatcher` resolves a handler for the given command and executes it.

```
use Georgeff\Bus\Dispatcher;

$dispatcher = new Dispatcher($resolver);

$dispatcher->dispatch(new SendEmail(
    to: 'user@example.com',
    subject: 'Welcome',
    body: 'Hello!',
));
```

### Handler Resolvers

[](#handler-resolvers)

A resolver takes a command class name and returns a callable handler. Two implementations are provided.

#### SimpleResolver

[](#simpleresolver)

Instantiates the handler directly. Suited for handlers with no constructor dependencies.

```
use Georgeff\Bus\Resolver\SimpleResolver;

$resolver = new SimpleResolver($locator);
```

#### PsrContainerResolver

[](#psrcontainerresolver)

Retrieves the handler from a PSR-11 container. Use this when handlers have dependencies.

```
composer require psr/container
```

```
use Georgeff\Bus\Resolver\PsrContainerResolver;

$resolver = new PsrContainerResolver($container, $locator);
```

### Handler Locators

[](#handler-locators)

A locator maps a command class name to a handler class name. Two implementations are provided.

#### InMemoryLocator

[](#inmemorylocator)

Uses an explicit command-to-handler map.

```
use Georgeff\Bus\Locator\InMemoryLocator;

$locator = new InMemoryLocator([
    SendEmail::class => SendEmailHandler::class,
]);
```

#### ClassNameLocator

[](#classnamelocator)

Resolves handlers by convention — appends `Handler` to the command class name. `SendEmail` resolves to `SendEmailHandler` in the same namespace.

```
use Georgeff\Bus\Locator\ClassNameLocator;

$locator = new ClassNameLocator();
```

### Middleware

[](#middleware)

The `MiddlewareAwareDispatcher` wraps any dispatcher with a middleware pipeline. Each middleware receives the command and a `$next` callable.

```
use Georgeff\Bus\MiddlewareAwareDispatcher;

$logging = function (object $command, callable $next): mixed {
    echo 'Dispatching ' . $command::class . PHP_EOL;

    $result = $next($command);

    echo 'Dispatched ' . $command::class . PHP_EOL;

    return $result;
};

$dispatcher = new MiddlewareAwareDispatcher(
    new Dispatcher($resolver),
    [$logging],
);

$dispatcher->dispatch(new SendEmail(/* ... */));
```

Middleware executes in the order provided. Each middleware can:

- Run logic before and after the handler
- Short-circuit by not calling `$next`
- Modify the return value

### Full Example

[](#full-example)

```
use Georgeff\Bus\Dispatcher;
use Georgeff\Bus\MiddlewareAwareDispatcher;
use Georgeff\Bus\Resolver\PsrContainerResolver;
use Georgeff\Bus\Locator\InMemoryLocator;

$locator = new InMemoryLocator([
    SendEmail::class => SendEmailHandler::class,
]);

$resolver = new PsrContainerResolver($container, $locator);

$dispatcher = new MiddlewareAwareDispatcher(
    new Dispatcher($resolver),
    [$logging, $transaction],
);

$dispatcher->dispatch(new SendEmail(
    to: 'user@example.com',
    subject: 'Welcome',
    body: 'Hello!',
));
```

License
-------

[](#license)

MIT

###  Health Score

40

—

FairBetter than 86% of packages

Maintenance88

Actively maintained with recent releases

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity46

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

Unknown

Total

1

Last Release

118d ago

### Community

Maintainers

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

---

Top Contributors

[![MikeGeorgeff](https://avatars.githubusercontent.com/u/6169468?v=4)](https://github.com/MikeGeorgeff "MikeGeorgeff (1 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

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

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

###  Alternatives

[butschster/cron-expression-generator

Cron expression generator

511.7M2](/packages/butschster-cron-expression-generator)

PHPackages © 2026

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