PHPackages                             blacksmith-project/command-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. [CLI &amp; Console](/categories/cli)
4. /
5. blacksmith-project/command-bus

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

blacksmith-project/command-bus
==============================

A PHP Library

v0.5.0(6y ago)047611MITPHPPHP ^7.3CI failing

Since Jan 11Pushed 4y agoCompare

[ Source](https://github.com/BlacksmithProject/CommandBus)[ Packagist](https://packagist.org/packages/blacksmith-project/command-bus)[ RSS](/packages/blacksmith-project-command-bus/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (6)Versions (10)Used By (1)

BlacksmithProject - CommandBus
==============================

[](#blacksmithproject---commandbus)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/a669b0bc1689833cbb884703b07b61a131db46daa758534966a902ada1278965/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b736d69746850726f6a6563742f436f6d6d616e644275732f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlacksmithProject/CommandBus/?branch=master)[![Code Coverage](https://camo.githubusercontent.com/2a57db22e831c99ecc08110884feb211bc0253179abfb000b3d4c8c9689173f6/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b736d69746850726f6a6563742f436f6d6d616e644275732f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlacksmithProject/CommandBus/?branch=master)[![Build Status](https://camo.githubusercontent.com/fb07a81a2fd5f79bcbdcf7d5bf919cd7a5944eb16a5eae9a06235ecc743de4a1/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f426c61636b736d69746850726f6a6563742f436f6d6d616e644275732f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/BlacksmithProject/CommandBus/build-status/master)

Why ?
-----

[](#why-)

In order to improve my skills, I'm doing my own implementation of a CommandBus.

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

[](#installation)

`composer require blacksmith-project/command-bus`

How to set it up?
-----------------

[](#how-to-set-it-up)

- Your handlers need to
    - be callable (implements an `__invoke()` method).
    - be named after the command they handle: ```
        $command = new AddSugarToCoffee();
        $handler = new AddSugarToCoffeeHandler();
        ```
- Handlers must be added to a `CommandHandlerMap`: ```
    $map = new SimpleCommandHandlerMap([$handler, $anotherHandler]);
    $map->add($yetAnotherHandler);
    ```
- Your `CommandBus` takes as parameter a `CommandHandlerMap`.

### How to do this in Symfony ?

[](#how-to-do-this-in-symfony-)

1. Declare your Handlers as a Service.
2. Tag them with a specific tag such as `my_app.command_handler`.
3. Declare your `CommandHandlerMap` as a Service.
4. Make it use the tagged `my_app.command_handler` services as arguments.
5. Declare your `CommandBus` as a Service.
6. Make it use the `CommandHandlerMap` as argument.

#### Example:

[](#example)

```
    # config/services.yaml

    ############
    # Commands #
    ############
    MyApp\Domain\ACommandHandler:
        tags:
            - 'my_app.command_handler'

    MyApp\Domain\AnothenCommandHandler:
        tags:
            - 'my_app.command_handler'

    ########################
    # CommandHandlerMapper #
    ########################
    BSP\CommandBus\SimpleCommandHandlerMap:
        arguments: [!tagged my_app.command_handler]

    ##############
    # CommandBus #
    ##############
    BSP\CommandBus\SimpleCommandBus:
        arguments:
            - BSP\CommandBus\SimpleCommandHandlerMap
```

How to use it?
--------------

[](#how-to-use-it)

Now, you only need to inject your `CommandBus` and execute commands.

### Example:

[](#example-1)

```
public function __construct(CommandBus $commandBus)
{
    $this->commandBus = $commandBus;
}

public function doSomethingFromCLI(): void
{
    $command = new DoSomething('please');

    $this->commandBus->execute($command);

    $output->writeln('command has been executed.');
}
```

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity51

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

Recently: every ~66 days

Total

8

Last Release

2415d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/de7b71eb47dae7485aa2ee1f9442d2a9c28f448b30cb6defe2a6835f1c651848?d=identicon)[ngdo-pro](/maintainers/ngdo-pro)

---

Top Contributors

[![ngdo-pro](https://avatars.githubusercontent.com/u/22030946?v=4)](https://github.com/ngdo-pro "ngdo-pro (43 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/blacksmith-project-command-bus/health.svg)

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

###  Alternatives

[wp-cli/wp-cli

WP-CLI framework

5.0k17.2M320](/packages/wp-cli-wp-cli)[consolidation/annotated-command

Initialize Symfony Console commands from annotated command class methods.

22569.8M19](/packages/consolidation-annotated-command)[chi-teck/drupal-code-generator

Drupal code generator

26947.8M5](/packages/chi-teck-drupal-code-generator)[seld/cli-prompt

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

24725.8M17](/packages/seld-cli-prompt)[illuminate/console

The Illuminate Console package.

12944.1M5.1k](/packages/illuminate-console)[php-tui/php-tui

Comprehensive TUI library heavily influenced by Ratatui

589747.0k6](/packages/php-tui-php-tui)

PHPackages © 2026

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