PHPackages                             itmedia/command-bus-bundle - 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. itmedia/command-bus-bundle

ActiveSymfony-bundle[CLI &amp; Console](/categories/cli)

itmedia/command-bus-bundle
==========================

Command bus

v0.5.0(4y ago)32.6k1MITPHPPHP ^7.4 || ^8.0CI failing

Since Oct 10Pushed 4y ago1 watchersCompare

[ Source](https://github.com/by25/CommandBusBundle)[ Packagist](https://packagist.org/packages/itmedia/command-bus-bundle)[ Docs](https://github.com/by25/CommandBusBundle)[ RSS](/packages/itmedia-command-bus-bundle/feed)WikiDiscussions master Synced 2w ago

READMEChangelog (4)Dependencies (2)Versions (9)Used By (0)

CommandBusBundle
================

[](#commandbusbundle)

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7ee42cd6729f31e6b31dfc709db0b28686dfac5cb9bf8644ba024bac10325a14/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f627932352f436f6d6d616e6442757342756e646c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/by25/CommandBusBundle/?branch=master)[![Build Status](https://camo.githubusercontent.com/d52d274793a603b0309ac212d45dbed2efb7dd20a8b7be92e7ae18ecc835d363/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f627932352f436f6d6d616e6442757342756e646c652f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/by25/CommandBusBundle/build-status/master)

Install
-------

[](#install)

```
composer require itmedia/command-bus-bundle
```

CommandBus
----------

[](#commandbus)

Пример регистрации сервиса, также смотри ниже добавление встроеных обработчиков комманд (Middleware):

```
services:

    app.command_bus:
        class: Itmedia\CommandBusBundle\CommandBus\CommandBus
        arguments: ["@itmedia_command_bus.container_handler_mapper"]
```

Middleware
----------

[](#middleware)

Middleware реализуют дополнительную обработку сообщений, например: валидацию, проверку прав доступа, логирование. Middleware должны реализовывать интерфейс `MiddlewareInterface`. В CommandBus при выполнении сообщения происходит его обработка подключенными Middleware. При не выполнении правил, должно всегда выбрасываться исключение.

Пример конфигурации:

```
services:
    app.command_bus:
        class: Itmedia\CommandBusBundle\CommandBus\CommandBus
        arguments: ["@itmedia_command_bus.container_handler_mapper"]
        calls:
            - [addMiddleware, ["@itmedia_command_bus.middleware_validation"]]
            - [addMiddleware, ["@app.middleware_access_control"]]

    # custom middleware
    app.middleware_access_control:
        class: AppBundle\Middleware\AccessControlMiddleware
```

---

Command
-------

[](#command)

Команда должна иметь интерфейс `Command`.

```
use Itmedia\CommandBusBundle\Command\Command;

class TestCommand implements Command
{
    //...

    public function commandName(): string
    {
        return 'test_command';
    }

}
```

Handlers могут иметь произвольную структуру, если используется, либо для единичного handler - `CommandHandler`

Пример конфигурации `CommandHandler`:

```
services:
    # по умолчанию будет вызван метод execute()
    AppBundle\Handler\MyHandler:
        public: true
        tags:
            - {name: command_handler, command: core_register_user }

    # явное указание методов
    AppBundle\Handler\NyHandler2:
        public: true
        tags:
            - {name: command_handler, command: core_register_user1, method: methodName1 }
            - {name: command_handler, command: core_register_user2, method: methodName2 }
            - {name: command_handler, command: core_register_user3, method: methodName3 }
```

Пример использования:

```
    $command = new CommandTest();
    $this->get('app.command_bus')->handle($command);
```

Валидация команд
----------------

[](#валидация-команд)

Для валидации команд средствами `symfony/validator` необходимо подключить `ValidationMiddleware` для `CommandBus`:

```
services:
    Itmedia\CommandBusBundle\CommandBus\CommandBus:
        arguments: ["@itmedia_command_bus.container_handler_mapper"]
        calls:
            - [addMiddleware, ["@itmedia_command_bus.middleware_validation"]]
```

Пример правил валидации команды:

```
use Itmedia\CommandBusBundle\Command\Command;
use Symfony\Component\Validator\Constraints as Assert;

class TestCommand implements Command
{

    /**
     * @NotBlank()
     */
    private string $username;

    /**
     * @NotBlank()
     * @Assert\Email()
     */
    private string $email;

    public function __construct(string $username, string $email)
    {
        $this->username = $username;
        $this->email = $email;
    }

    public function commandName(): string
    {
        return 'test_command';
    }

    public function getUsername(): string
    {
        return $this->username;
    }

    public function getEmail(): string
    {
        return $this->email;
    }

}
```

Если комманда не проходит валидацию выбрасывается исключение `ValidationException`

Установка значений свойств комманды из массива
----------------------------------------------

[](#установка-значений-свойств-комманды-из-массива)

`HandlePropertiesFormArrayTrait` - вспомогательный трейт для устаовки значений по ключу из массива в свойства команды. Название ключа должно соответсвовать названию свойства.

```
use Itmedia\CommandBusBundle\Command\Command;
use Itmedia\CommandBusBundle\Command\HandlePropertiesFormArrayTrait;

class TestCommand implements Command
{

    use HandlePropertiesFormArrayTrait;

    // ....

    public function __construct($id, array $data)
    {
        $this->handleProperties($data);
        $this->id = $id;
    }

}
```

###  Health Score

32

—

LowBetter than 69% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity63

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

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

Total

7

Last Release

1743d ago

PHP version history (4 changes)v0.1.0PHP ^5.6 || ^7.0

v0.3.0PHP ^7.1.3

v0.4.1PHP ^8.0.8

v0.5.0PHP ^7.4 || ^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1336525?v=4)[Andrei Kulikovski](/maintainers/by25)[@by25](https://github.com/by25)

---

Top Contributors

[![akulikouski](https://avatars.githubusercontent.com/u/55628778?v=4)](https://github.com/akulikouski "akulikouski (2 commits)")[![by25](https://avatars.githubusercontent.com/u/1336525?v=4)](https://github.com/by25 "by25 (2 commits)")[![DKholevinsky](https://avatars.githubusercontent.com/u/10176956?v=4)](https://github.com/DKholevinsky "DKholevinsky (2 commits)")

---

Tags

command-busphpsymfony-bundle

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/itmedia-command-bus-bundle/health.svg)

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

###  Alternatives

[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k17.5M373](/packages/easycorp-easyadmin-bundle)[rcsofttech/audit-trail-bundle

Enterprise-grade, high-performance Symfony audit trail bundle. Automatically track Doctrine entity changes with split-phase architecture, multiple transports (HTTP, Queue, Doctrine), and sensitive data masking.

1155.2k](/packages/rcsofttech-audit-trail-bundle)[web-auth/webauthn-symfony-bundle

FIDO2/Webauthn Security Bundle For Symfony

65474.5k9](/packages/web-auth-webauthn-symfony-bundle)[2lenet/crudit-bundle

The easy like Crud'it Bundle.

1715.6k12](/packages/2lenet-crudit-bundle)[ecotone/symfony-bundle

Ecotone for Symfony — CQRS, Event Sourcing, Sagas, Durable Workflows, and Outbox on top of Symfony Messenger, via PHP attributes.

11241.1k1](/packages/ecotone-symfony-bundle)

PHPackages © 2026

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