定制 madewithlove/tactician-laravel 二次开发

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

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

madewithlove/tactician-laravel

最新稳定版本:1.0.3

Composer 安装命令:

composer require madewithlove/tactician-laravel

包简介

Integrate tactician with Laravel 5

关键字:

README 文档

README

Build Status Latest Stable Version Total Downloads Scrutinizer Quality Score Code Coverage

Introduction

This packages is a replacement for Laravel 5's default command bus using tactician.

Default middleware

  • LockingMiddleware (block commands from running inside commands)
  • TransactionMiddleware (Run all commands in a database transaction and rolls back incase of failure)

Command Handling

By default commands will be resolved as followed:

Acme\Jobs\Foo => Acme\Listeners\Foo
Acme\Foo\Jobs\Bar => Acme\Foo\Listeners\Bar

All command handlers are resolved out of the container which mean you can use all kind of Laravel goodies.

Install

$ composer require madewithlove/tactician-laravel

Laravel <= 5.4

Add the service provider to config/app.php:

Madewithlove\Tactician\ServiceProvider::class,

In case you want to tweak the middleware you should publish the package configuration:

php artisan vendor:publish --provider="Madewithlove\Tactician\ServiceProvider"

Usage

Writing commands

A command always consists out of two parts: the command and the handler.

// Products\Jobs\CalculatePriceForQuantity
class CalculatePriceForQuantity
{
    public $price;

    public $amount;

    public function __construct($price, $amount = 1)
    {
        $this->price = $price;
        $this->amount = $amount;
    }
}

use Products\Jobs\CalculatePriceForQuantity as Job;

// Products\Listeners\CalculatePriceForQuantity
class CalculatePriceForQuantity
{
    public function handle(Job $job)
    {
        return $job->amount * $job->price;
    }
}

Overriding the command handling logic

If you're not happy with the default logic shipped in this package you can overwrite it easily by rebinding the League\Tactician\Handler\CommandHandlerMiddleware. You do this by adding the following to your application's service provider, refer to Tactician's documentation for options.

public function register()
{
    $this->app->bind(CommandHandlerMiddleware::class, function () {
        // Return your own implementation of CommandHandlerMiddleware here.
    });
}

Middleware

This package includes a couple middleware specific to Laravel, you can choose to use these.

TransactionMiddleware

This middleware is included by default. It means all your commands are handled inside of a database transaction, and if an error occurs it will rollback the transaction.

It's quite common for a command to throw an exception that is caught higher up the chain so a certain action can be performed (such as displaying an error message) but still perform some kind of database interaction. For cases such as this you can make use of the Madewithlove\Tactician\Contracts\IgnoresRollback interface. Simply implement it on your exception and no rollbacks will be performed!

Note: This middleware only runs the main database connection in a transaction, if you use multiple connections you will need to come up with a custom solution.

Testing

$ composer test

License

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

madewithlove/tactician-laravel 适用场景与选型建议

madewithlove/tactician-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 62.69k 次下载、GitHub Stars 达 20, 最近一次更新时间为 2015 年 12 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 madewithlove/tactician-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 madewithlove/tactician-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 madewithlove/tactician-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 62.69k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 20
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 1

GitHub 信息

  • Stars: 20
  • Watchers: 10
  • Forks: 4
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2015-12-23