PHPackages                             robotusers/cakephp-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. robotusers/cakephp-tactician

ActiveCakephp-plugin[Framework](/categories/framework)

robotusers/cakephp-tactician
============================

CakePHP Tactician plugin

0.4.0(3y ago)94.9k2[3 issues](https://github.com/robotusers/cakephp-tactician/issues)MITPHPPHP &gt;=7.2

Since Jul 24Pushed 3y ago1 watchersCompare

[ Source](https://github.com/robotusers/cakephp-tactician)[ Packagist](https://packagist.org/packages/robotusers/cakephp-tactician)[ Docs](https://github.com/robotusers/cakephp-tactician)[ RSS](/packages/robotusers-cakephp-tactician/feed)WikiDiscussions master Synced 2d ago

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

CakePHP Tactician
=================

[](#cakephp-tactician)

[![Software License](https://camo.githubusercontent.com/074b89bca64d3edc93a1db6c7e3b1636b874540ba91d66367c0e5e354c56d0ea/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e737667)](LICENSE)[![Build Status](https://camo.githubusercontent.com/2a4fb2bc5a37423f810414809ab5964981367c3419a51a6575a98723d29cdf6f/68747470733a2f2f7472617669732d63692e6f72672f726f626f7475736572732f63616b657068702d74616374696369616e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/robotusers/cakephp-tactician)[![codecov](https://camo.githubusercontent.com/78361b754a64d12816958689790ee0fe5ec4be846435a482b79b7c33f69eef36/68747470733a2f2f636f6465636f762e696f2f67682f726f626f7475736572732f63616b657068702d74616374696369616e2f6272616e63682f6d61737465722f67726170682f62616467652e737667)](https://codecov.io/gh/robotusers/cakephp-tactician)

CakePHP plugin for `league/tactician`.

**NOTE: The plugin is under development.**

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

[](#installation)

```
composer require robotusers/cakephp-tactician
bin/cake plugin load Robotusers/Tactician

```

Using the plugin
----------------

[](#using-the-plugin)

### CakePHP integration

[](#cakephp-integration)

This plugin provides Controller and Model integration through [Commander](https://github.com/robotusers/commander) library.

Commander is a command bus abstraction library for PHP which enables you to decouple your code from a concrete command bus implementation.

#### Using the Commander (PHP 7.1+)

[](#using-the-commander-php-71)

Install `robotusers/commander`:

```
composer require robotusers/commander

```

Set up your controllers:

```
use Cake\Controller\Controller;
use Robotusers\Commander\CommandBusAwareInterface;
use Robotusers\Tactician\Bus\CommandBusAwareTrait;

class OrdersController extends Controller implements CommandBusAwareInterface
{
   use CommandBusAwareTrait;

   public function makeOrder()
   {
        // ...
        $command = new MakeOrderCommand($data);
        $this->handleCommand($command);
        // ...

        // or using quick convention enabled command handling:
        $this->handleCommand('MakeOrder', $data);
        // ...
   }

}
```

For more information, read [the docs](https://github.com/robotusers/commander/blob/master/README.md).

Next you should configure the command bus which will be injected into your controllers and models that implement the `CommandBusAwareInterface`.

#### Console (CakePHP 3.6+)

[](#console-cakephp-36)

For console integration Tactician plugin provides a `CommandFactory` that injects a command bus into compatible console shells and commands.

Set up your `CommandRunner` as below:

```
use App\Application;
use Cake\Console\CommandRunner;
use Cake\Console\CommandFactory;
use Tactician\Console\CommandFactory as TacticianCommandFactory;

$application = new Application(dirname(__DIR__) . '/config');
$cakeFactory = new CommandFactory(); // or any other custom factory (ie. CakePHP DI plugin DIC-compatible factory)
$factory = new TacticianCommandFactory($cakeFactory, $application);

$runner = new CommandRunner($application, 'cake', $factory);
exit($runner->run($argv));
```

#### Application hook (CakePHP 3.3+)

[](#application-hook-cakephp-33)

If your application supports middleware you can configure the command bus using an application hook.

```
use Cake\Http\BaseApplication;
use League\Tactician\CommandBus;
use Robotusers\Tactician\Core\BusApplicationInterface;
use Robotusers\Tactician\Core\BusMiddleware;

class Application extends BaseApplication implements BusApplicationInterface
{
    public function commandBus()
    {
        $bus = new CommandBus([
            // your middleware
        ]);

        return $bus;
    }

    public function middleware($middleware)
    {
        // ...
        $middleware->add(new BusMiddleware($this));
        // ...

        return $middleware;
    }
}
```

You can use helper factory methods for building `CommandBus` or CakePHP convention enabled `CommandHandlerMiddleware`:

```
use Robotusers\Tactician\Bus\Factory;

public function commandBus()
{
    return Factory::createCommandBus([
        // your middleware
        Factory::createCommandHandlerMiddleware();
    ]);
}
```

The command bus configured here will be injected into controllers and models in `Model.initialize` and `Controller.initialize` event listener.

#### Bootstrap

[](#bootstrap)

If you're still on pre 3.3 stack you can set up the listener in your `bootstrap.php` file.

You can use build in *quick start* class:

```
// bootstrap.php

use Robotusers\Tactician\Event\QuickStart;

QuickStart::setUp($commandBus);
```

`QuickStart` can load simple CakePHP convention enabled bus if it hasn't been provided:

```
// bootstrap.php

use Robotusers\Tactician\Event\QuickStart;

QuickStart::setUp();
```

### Conventions locator

[](#conventions-locator)

CakePHP Conventions locator will look for command handlers based on a convention, that commands should reside under `App\Model\Command\` namespace and be suffixed with `Command` string and handlers should reside under `App\Model\Handler\` namespace and be suffixed with `Handler` string.

```
//CakePHP convention locator
$locator = new ConventionsLocator();
$extractor = new ClassNameExtractor();
$inflector = new HandleClassNameInflector();

$commandBus = new CommandBus(
    [
        new CommandHandlerMiddleware($extractor, $locator, $inflector)
    ]
);
```

In this example `App\Model\Command\MakeOrderCommand` command will map to `App\Model\Handler\MakeOrderHandler` handler.

You can change default namespace and suffix using configuration options:

```
$locator = new ConventionsLocator([
    'commandNamespace' => 'Command',
    'commandSuffix' => '',
    'handlerNamespace' => 'Handler',
    'handlerSuffix' => '',
]);
```

In this example `App\Command\MakeOrder` command will map to `App\Handler\MakeOrder` handler. Note a different namespace and no suffix.

### Transaction middleware

[](#transaction-middleware)

Transaction middleware is a wrapper for CakePHP `ConnectionInterface::transactional()`. You need to provide a list of supported commands.

A list supports FQCN or convention supported name (eq `Plugin.Name`).

This will wrap only `Foo` and `Bar` commands in a transaction:

```
//default connection
$connection = ConnectionManager::get('default');

$commandBus = new CommandBus(
    [
        //CakePHP transaction middleware with a connection and a list of commands.
        new TransactionMiddleware($connection, [
            FooCommand::class,
            'My/Plugin.Bar',
        ]),
        $commandHandlerMiddleware
    ]
);
```

You can include all commands by setting the `$commands` argument to `true` and exclude only some commands.

This will wrap all commands in a transaction with an exception for `Foo` and `Bar` commands:

```
$middleware = new TransactionMiddleware($connection, true, [
    FooCommand::class,
    'My/Plugin.Bar',
]),
```

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance13

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity52

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

Total

4

Last Release

1318d ago

PHP version history (2 changes)0.1.0PHP &gt;=5.6

0.4.0PHP &gt;=7.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/7437773?v=4)[Robert Pustułka](/maintainers/robertpustulka)[@robertpustulka](https://github.com/robertpustulka)

---

Top Contributors

[![robertpustulka](https://avatars.githubusercontent.com/u/7437773?v=4)](https://github.com/robertpustulka "robertpustulka (49 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/robotusers-cakephp-tactician/health.svg)

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

###  Alternatives

[cakephp/database

Flexible and powerful Database abstraction library with a familiar PDO-like API

9826.4M46](/packages/cakephp-database)[cakephp/orm

CakePHP ORM - Provides a flexible and powerful ORM implementing a data-mapper pattern.

151252.5k82](/packages/cakephp-orm)[cakephp/utility

CakePHP Utility classes such as Inflector, String, Hash, and Security

12129.0M83](/packages/cakephp-utility)[cakephp/datasource

Provides connection managing and traits for Entities and Queries that can be reused for different datastores

4726.4M15](/packages/cakephp-datasource)[cakephp/cache

Easy to use Caching library with support for multiple caching backends

518.7M24](/packages/cakephp-cache)[cakephp/log

CakePHP logging library with support for multiple different streams

267.8M14](/packages/cakephp-log)

PHPackages © 2026

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