定制 spekkionu/tactician-container-selfhandling 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

spekkionu/tactician-container-selfhandling

Composer 安装命令:

composer require spekkionu/tactician-container-selfhandling

包简介

Container-Aware Self-Handling commands for Tactician Command Bus

README 文档

README

Latest Stable Version Build Status License Code Coverage Scrutinizer Code Quality SensioLabsInsight

Install

Via Composer

$ composer require spekkionu/tactician-container-selfhandling

If you want to use the container aware commands you will also need to install league/container

Usage

Add MiddleWare

use League\Tactician\CommandBus;
use Spekkionu\Tactician\SelfExecuting\SelfExecutionMiddleware;

$commandBus = new CommandBus([
    // any other pre-execution middleware
    new SelfExecutionMiddleware(),
    // other middleware to handle non-self-executing commands
    // any other post-execution middleware
]);

Create a Command

Your commands must implement Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand and have a handle() method.

The handle method must have no parameters.

use Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand;

/**
 * Class ExampleSelfExecutingCommand
 */
class ExampleSelfExecutingCommand implements SelfExecutingCommand
{
    /**
     * @return string
     */
    public function handle()
    {
        // do work here
    }
}

Run Command

$commandBus->handle(new ExampleSelfExecutingCommand());

Container-Aware Self-Executing Commands

Container aware commands will have dependencies injected into the handle() method from league/container.

use League\Container\Container;
use League\Tactician\CommandBus;
use Spekkionu\Tactician\SelfExecuting\SelfExecutionMiddleware;

// Setup the Container
$container = new Container();
$container->delegate(
    new \League\Container\ReflectionContainer
);
$container->add('Logger', function() {
    return new Logger();
});

// Setup the command bus
$commandBus = new CommandBus([
    // any other pre-execution middleware
    new ContainerAwareSelfExecutionMiddleware($container),
    // other middleware to handle non-self-executing commands
    // any other post-execution middleware
]);
use Spekkionu\Tactician\SelfExecuting\SelfExecutingCommand;

/**
 * Class ExampleSelfExecutingCommand
 */
class ExampleSelfExecutingCommand implements SelfExecutingCommand
{
    /**
     * The logger will be injected automatically
     * @return string
     */
    public function handle(Logger $logger)
    {
        $logger->log('log message');
    }
}
$commandBus->handle(new ExampleSelfExecutingCommand());

Testing

$ composer test

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 223
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-26

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固