infw/tactician-adapter

此包已被废弃,不再维护。未建议替代包。

League tactician 命令总线适配器,适用于 zend-expressive 框架。

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 命令总线适配器,适用于 zend-expressive 框架

!!!! 此包不再维护,建议使用 https://github.com/antidot-framework/tactician-adapter

开始使用

安装

composer require infw/tactician-adapter

您可以使用 Zend 配置管理器在 expressive 模块化应用程序中激活。

配置

在配置自动加载目录内创建 command-bus.global.php 文件。

<?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
        ],
    ],
];

示例命令和处理程序。

<?php

namespace App\Command;

class PingCommand
{

}
<?php

namespace App\Handler;

use App\Command\PingCommand;

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

您可以使用 InFw\TacticianAdapter\Action\AbstractAction 作为基本动作。

<?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())]);
    }
}

修改命令总线

您可以根据项目需求修改整个命令总线。

这是默认配置。

<?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,

        ],
    ],
];