PHPackages                             dersonsena/yii2-tactician - 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. [Framework](/categories/framework)
4. /
5. dersonsena/yii2-tactician

Abandoned → [astrotechlabs/yii2-tactician](/?search=astrotechlabs%2Fyii2-tactician)Project[Framework](/categories/framework)

dersonsena/yii2-tactician
=========================

Yii 2 Command Bus pattern implementation

1.2.5(4y ago)61.5k1[1 issues](https://github.com/AstrotechLabs/yii2-tactician/issues)MITPHPPHP &gt;=7.4

Since May 17Pushed 2y ago1 watchersCompare

[ Source](https://github.com/AstrotechLabs/yii2-tactician)[ Packagist](https://packagist.org/packages/dersonsena/yii2-tactician)[ Docs](https://github.com/dersonsena/yii2-command-bus)[ RSS](/packages/dersonsena-yii2-tactician/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (9)Dependencies (5)Versions (10)Used By (0)

Yii2 Tactician Command Bus
==========================

[](#yii2-tactician-command-bus)

[![Packagist PHP Version Support](https://camo.githubusercontent.com/fc5cd300f78553226c6c6b18c421f9dbe8eae71fdde00273798c2a80369ea159/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646572736f6e73656e612f796969322d74616374696369616e)](https://camo.githubusercontent.com/fc5cd300f78553226c6c6b18c421f9dbe8eae71fdde00273798c2a80369ea159/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f7068702d762f646572736f6e73656e612f796969322d74616374696369616e)[![GitHub stars](https://camo.githubusercontent.com/5cbf036f98468f48e052d70e3fa5bb49c648ccca66f4365b6d28360f264ef0a2/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f73746172732f646572736f6e73656e612f796969322d74616374696369616e)](https://github.com/dersonsena/yii2-tactician/stargazers)[![GitHub forks](https://camo.githubusercontent.com/c1c77cf66f4edf112a4cff5b737ec1e9a1a71a585ad9d2d8bc6ebeadcff42e8f/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f666f726b732f646572736f6e73656e612f796969322d74616374696369616e)](https://github.com/dersonsena/yii2-tactician/network)[![GitHub repo size](https://camo.githubusercontent.com/4b8bd7f0984ecaec7411657220c56d3420f192aaee3ce82d4f859c8aa88dcd10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f646572736f6e73656e612f796969322d74616374696369616e)](https://camo.githubusercontent.com/4b8bd7f0984ecaec7411657220c56d3420f192aaee3ce82d4f859c8aa88dcd10/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f7265706f2d73697a652f646572736f6e73656e612f796969322d74616374696369616e)[![GitHub license](https://camo.githubusercontent.com/c83f60882e3b183baf00cbc14d610b6231048d043316dc91bf3ee6151e696d7d/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c6963656e73652f646572736f6e73656e612f796969322d74616374696369616e)](https://github.com/dersonsena/yii2-tactician/blob/master/LICENSE)

This is a Yii Framework 2 Wrapper/Adapter for [Tactician Command Bus Library](https://tactician.thephpleague.com/). It provides an easy way to use the command bus pattern in Yii2 Based apps.

When should I use Command Bus?
------------------------------

[](#when-should-i-use-command-bus)

> Tactician is a great fit if you’ve got a service layer. If you’re not sure what a service layer is, Martin Fowler’s PoEAA is a good starting point. Tactician’s author also did a talk on the subject.
>
> Commands really help capture user intent. They’re also a great stand-in for the models when it comes to forms or serializer libraries that expect getter/setter objects.
>
> The command bus itself is really easy to decorate with extra behaviors, like locking or database transactions so it’s very easy to extend with plugins.
>
> By: tactician.thephpleague.com

When should I NOT use it?
-------------------------

[](#when-should-i-not-use-it)

> If you’ve got a very small app that doesn’t need a service layer, then Tactician won’t offer much to you.
>
> If you’re already using a tool that provides a command bus (like Broadway), you’re probably okay there too.
>
> *By: tactician.thephpleague.com*

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

[](#installation)

```
$ composer require astrotechlabs/yii2-tactician
```

Setup
-----

[](#setup)

First you must have configure your [Yii Dependency Injection Container](https://www.yiiframework.com/doc/guide/2.0/en/concept-di-container) to be able to use Command and Handler classes within it.

You should have something like this in your `config/web.php`:

```
$config = [
    'id' => 'your-app-id',
    //...
    'container' => [
        'definitions' => [
            MyClassCommand::class => MyClassHandler::class
        ]
    ],
    'components' => [
        //...
    ]
];
```

**IMPORTANT:** you must follow the conventions below:

- Your **Command** class must be suffixed by `Command`;
- Your **Handler** class must be: `Same Command Class Name` + `Without Command Suffix` + `Handler`.

The last one is register [Yii2TacticianCommandBus](./src/Yii2TacticianCommandBus.php) component in your `config/web.php` file, as below:

```
$config = [
    'id' => 'your-app-id',
    //...
    'container' => [
        'definitions' => [
            MyClassCommand::class => MyClassHandler::class
        ]
    ],
    'components' => [
        'commandBus' => [
            'class' => AstrotechLabs\Yii2Tactician\Yii2TacticianCommandBus::class
        ],
        // other components...
    ]
];
```

How to Use
----------

[](#how-to-use)

### Mapping Command and Handler Classes

[](#mapping-command-and-handler-classes)

Define a `Command` class somewhere in your application, for example:

```
class MyClassCommand
{
    public $someParam;
    public $someOtherParam;

    public function __construct($someParam, $someOtherParam = 'defaultValue')
    {
    	$this->someParam = $someParam;
        $this->someOtherParam = $someOtherParam;
    }
}
```

Define your `Handler` class should be something like:

```
class MyClassHandler
{
    public function handle(MyClassCommand $command)
    {
    	// do command stuff here!
        // we can use $command->someParam and $this->someOtherParam
    }
}
```

Now we can use this command in controllers or wherever you want:

```
public function actionDoSomething()
{
    $queryParam = Yii::$app->getRequest()->get('some_param');

    // Here the magic happens! =)
    $result = Yii::$app->commandBus->handle(new MyClassCommand($queryParam));

    if ($result === true) {
    	return $this->redirect(['go/to/some/place']);
    }

    return $this->render('some-awesome-view');
}
```

### Using String Path

[](#using-string-path)

You can use a command class as **String Path** instead of concrete object. For this case, just do:

```
$config = [
    'id' => 'your-app-id',
    //...
    'container' => [
        'definitions' => [
            // you can use any string here.
            'awesome.alias.to.be.called.anywhere' => MyClassHandler::class
        ]
    ],
    'components' => [
        //...
    ]
];
```

Your **Handle Class** should be as follows:

```
class MyClassHandler implements AstrotechLabs\Yii2Tactician\Handler
{
    public function handle(MyClassCommand $command)
    {
    	// do command stuff here!
        // we can use $command->someParam and $this->someOtherParam
    }

    public function commandClassName(): string
    {
        return MyClassCommand::class;
    }
}
```

> **IMPORTANT:** in this way your **Handler Class** MUST implements the [AstrotechLabs\\Yii2Tactician\\Handler](src/Handler.php) interface and your **Command Class** MUST implements [AstrotechLabs\\Yii2Tactician\\Command](src/Command.php).

Your controller action or anywhere else:

```
public function actionDoSomething()
{
    $result = Yii::$app->commandBus->handle('awesome.alias.to.be.called.anywhere', [
        'someParam' => 'abc',
        'someOtherParam' => 'def'
    ]);

    // .. other logics
}
```

Under the hood the Command Bus System will call:

```
MyClassHandler::handle($command);
```

where `$command` argument is created inside that like:

```
MyClassCommand::create([someParam' => 'abc', 'someOtherParam' => 'def']);
```

Enjoy =).

Authors
-------

[](#authors)

- [Kilderson Sena](https://github.com/dersonsena) - Owner - [Yii Academy](https://www.yiiacademy.com.br)

See also the list of [contributors](https://github.com/dersonsena/yii2-tactician/contributors) who participated in this project.

Contributing
------------

[](#contributing)

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Licence
-------

[](#licence)

This package is released under the [MIT](https://choosealicense.com/licenses/mit/) License. See the bundled [LICENSE](./LICENSE) for details.

References
----------

[](#references)

- [thephpleague/tactician](https://github.com/thephpleague/tactician)
- [pavelmics/YiiTactician](https://github.com/pavelmics/YiiTactician/blob/master/README.md)

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance17

Infrequent updates — may be unmaintained

Popularity21

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity57

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

Recently: every ~61 days

Total

9

Last Release

1568d ago

PHP version history (2 changes)1.0.0PHP ^7.4

1.2.5PHP &gt;=7.4

### Community

Maintainers

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

---

Top Contributors

[![dersonsena](https://avatars.githubusercontent.com/u/9482515?v=4)](https://github.com/dersonsena "dersonsena (15 commits)")

---

Tags

command-buscommand-handlercqrsevent-busyii2yii2-extensionyii2-frameworkframeworkyii2command busservice layercqrscommand handler

###  Code Quality

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/dersonsena-yii2-tactician/health.svg)

```
[![Health](https://phpackages.com/badges/dersonsena-yii2-tactician/health.svg)](https://phpackages.com/packages/dersonsena-yii2-tactician)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[tecnocen/yii2-formgenerator

Yii 2 Library to configure form generator

145.7k](/packages/tecnocen-yii2-formgenerator)

PHPackages © 2026

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