infw/tactician-adapter

This package is abandoned and no longer maintained. No replacement package was suggested.

League tactician command bus adapter for zend-expressive framework.

2.0.0 2019-02-25 10:55 UTC

This package is auto-updated.

Last update: 2020-10-07 15:40:37 UTC


README

Scrutinizer Code Quality Build Status SensioLabsInsight

League tactician command bus adapter for zend-expressive framework.

!!!! This package is not more mantained in favor of https://github.com/antidot-framework/tactician-adapter

Getting started

Installation

composer require infw/tactician-adapter

You can activate using Zend config-manager in a expressive modular application.

Config

Create command-bus.global.php file inner config autoload directory.

<?php

// command-bus.global.php

return [
    'dependencies' => [
        'factories' => [
            \Psr\Log\LoggerInterface => new Logger('app') // LoggerInterface is required, add your own logger instance.
        ]
    ],
    'command-bus' => [
        'handler-map' => [
            \App\Command\PingCommand::class => \App\Handler\PingHandler::class
        ],
    ],
];

Example command and handler.

<?php

namespace App\Command;

class PingCommand
{

}
<?php

namespace App\Handler;

use App\Command\PingCommand;

class PingHandler
{
    public function __invoke(PingCommand $command)
    {
        return time();
    }
}

You can use InFw\TacticianAdapter\Action\AbstractAction as base action.

<?php

namespace App\Action;

use App\Command\PingCommand;
use InFw\TacticianAdapter\Action\AbstractAction;
use Interop\Http\ServerMiddleware\DelegateInterface;
use Zend\Diactoros\Response\JsonResponse;
use Psr\Http\Message\ServerRequestInterface;

class PingAction extends AbstractAction
{
    public function process(ServerRequestInterface $request, DelegateInterface $delegate)
    {
        return new JsonResponse(['ack' => $this->bus->handle(new PingCommand())]);
    }
}

Modify Command Bus

You can modify the entire command bus to meet the needs of your project.

This is default config.

<?php

return [
    'command-bus' => [
        'locator' => \League\Tactician\Handler\Locator\HandlerLocator::class,
        'inflector' => \League\Tactician\Handler\MethodNameInflector\MethodNameInflector::class,
        'extractor' => \League\Tactician\Handler\CommandNameExtractor\CommandNameExtractor::class,
        'formatter' => \League\Tactician\Logger\Formatter\Formatter::class,
        'middleware' => [
            \League\Tactician\Plugins\LockingMiddleware::class,
            \League\Tactician\Logger\LoggerMiddleware::class,
            \League\Tactician\CommandEvents\EventMiddleware::class,

        ],
    ],
];