PHPackages                             code-mine/tactician-module - 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. code-mine/tactician-module

ActiveLibrary[Framework](/categories/framework)

code-mine/tactician-module
==========================

ZF2 Module to use the League of Extraordinary Packages' Tactician library - flexible command bus implementation

2.0.1(9y ago)03101MITPHPPHP ^5.5 || ^7.0

Since May 20Pushed 9y ago4 watchersCompare

[ Source](https://github.com/Code-Mine-Development/TacticianModule)[ Packagist](https://packagist.org/packages/code-mine/tactician-module)[ RSS](/packages/code-mine-tactician-module/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (5)Versions (15)Used By (1)

Tactician ZF2 Module
====================

[](#tactician-zf2-module)

[![Build Status](https://camo.githubusercontent.com/730a494395bf3ce1117508c337168c37a27e4517cc3737c5aeedc2406a120b30/68747470733a2f2f7472617669732d63692e6f72672f6d696b656d69782f54616374696369616e4d6f64756c652e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/mikemix/TacticianModule) [![Scrutinizer Code Quality](https://camo.githubusercontent.com/50e36140228d4aac1e677923289380dd5f68eabc0b862430d8d6c98799297cb3/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696b656d69782f54616374696369616e4d6f64756c652f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mikemix/TacticianModule/?branch=master) [![Code Coverage](https://camo.githubusercontent.com/70210778584d49afb2040e138060b475b9b203f248e1042ee2fa36a45b27f036/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d696b656d69782f54616374696369616e4d6f64756c652f6261646765732f636f7665726167652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/mikemix/TacticianModule/?branch=master) [![Dependency Status](https://camo.githubusercontent.com/01408041d4bc196ea400bf7a2e365c9a097c591683a7e8989a6412eec963f4b2/68747470733a2f2f7777772e76657273696f6e6579652e636f6d2f757365722f70726f6a656374732f3535366235613130363336353332303032366661343530302f62616467652e7376673f7374796c653d666c6174)](https://www.versioneye.com/user/projects/556b5a106365320026fa4500) [![Latest Stable Version](https://camo.githubusercontent.com/c3dd4ffc497a1462bc958a3522f7783f0fbd3e021fb95b1f8828afc3e2cc172a/68747470733a2f2f706f7365722e707567782e6f72672f6d696b656d69782f74616374696369616e2d6d6f64756c652f762f737461626c65)](https://packagist.org/packages/mikemix/tactician-module) [![Total Downloads](https://camo.githubusercontent.com/819294c1da53fee29e1dbb422462fe2b91921b8aba2f2887fc25a7d8cb95569f/68747470733a2f2f706f7365722e707567782e6f72672f6d696b656d69782f74616374696369616e2d6d6f64756c652f646f776e6c6f616473)](https://packagist.org/packages/mikemix/tactician-module) [![License](https://camo.githubusercontent.com/26529d3b4befa087cd65871199a350538c7d064742adb17e54afb5720fc67c5b/68747470733a2f2f706f7365722e707567782e6f72672f6d696b656d69782f74616374696369616e2d6d6f64756c652f6c6963656e7365)](https://packagist.org/packages/mikemix/tactician-module)

Wrapper module for easy use of the [Tactician](http://tactician.thephpleague.com/) Command Bus in your ZF2 applications.
------------------------------------------------------------------------------------------------------------------------

[](#wrapper-module-for-easy-use-of-the-tactician-command-bus-in-your-zf2-applications)

### Installation

[](#installation)

Best install with Composer:

`composer require mikemix/tactician-module`

### Register as ZF2 module inside your `config/application.config.php` file:

[](#register-as-zf2-module-inside-your-configapplicationconfigphp-file)

```
    'modules' => [
        'YourApplicationModule',
        'TacticianModule',
    ],
```

### Using

[](#using)

The module presents a **Controller Plugin** called `tacticianCommandBus()` for easy use of dispatching commands. If no command object is passed to it, the CommandBus object will be returned. If you pass the command however, it will be passed over to the CommandBus and handled, and the output from the handler will be returned.

You can type hint this plugin in your controller, for example: `@method \League\Tactician\CommandBus|mixed tacticianCommandBus(object $command)`.

```
// Real life example.
// Namespaces, imports, class properties skipped for brevity

class LoginController extends AbstractActionController
{
    public function indexAction()
    {
        if ($this->request->isPost()) {
            $this->form->setData($this->request->getPost());

            if ($this->form->isValid()) {
                $command = new UserLoginCommand(
                    $this->form->getLogin(),
                    $this->form->getPassword()
                ));

                try {
                    $this->tacticianCommandBus($command);
                    return $this->redirect()->toRoute('home');
                } catch (\Some\Kind\Of\Login\Failure $exception) {
                    $this->flashMessenger()->addErrorMessage($exception->getMessage());
                    return $this->redirect()->refresh();
                }
            }
        }

        $view = new ViewModel();
        $view->setVariable('form', $this->form);
        $view->setTemplate('app/login/index');

        return $view;
    }
}

final class UserLoginCommand
{
    public function __construct($login, $password)
    {
        $this->login = $login;
        $this->password = $password;
    }
}

final class UserLoginHandler
{
    // constructor skipped for brevity

    public function handle(UserLoginCommand $command)
    {
        $this->authenticationService->login($command->username, $command->password);
    }
}
```

If you need to inject the command bus into your service layer or similar, then simply grab from the **Service Manager** using the FQCN of the `CommandBus`.

```
