承接 jagarsoft/laravel-tactician 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jagarsoft/laravel-tactician

Composer 安装命令:

composer require jagarsoft/laravel-tactician

包简介

Laravel implementation of the Tactician Command Bus

README 文档

README

Laravel Tactician in an implementation of the Command Bus Tactician by Ross Tuck.

Build Status Code Coverage Packagist Downloads Scrutinizer Code Quality

Warning

Original package has been abandoned. The author has designated this repository as an official replacement. Current tag deprecated Joselfonseca namespace. Next release will be named to Jagarsoft.

Installation

To install this update your composer.json run composer require jagarsoft/laravel-tactician

>= laravel5.5

ServiceProvider will be attached automatically.

Other

Once the dependencies have been downloaded, add the service provider to your config/app.php file:

    'providers' => [
        ...
        Joselfonseca\LaravelTactician\Providers\LaravelTacticianServiceProvider::class
        ...
    ]

You are done with the installation!

Usage

To use the command bus you can resolve the bus from the laravel container like so:

    $bus = app('Joselfonseca\LaravelTactician\CommandBusInterface');

Or you can inject it into a class constructor:

    use Joselfonseca\LaravelTactician\CommandBusInterface;

    class MyController extends BaseController
    {

        public function __construct(CommandBusInterface $bus)
        {
            $this->bus = $bus;
        }

    }

Once you have the bus instance you can add your handler for the command to be dispatched:

    $bus->addHandler('SomeCommand', 'SomeHandler');

Now you can dispatch the command with the middleware:

    // first parameter is the class name of the command
    // Second parameter is an array of input data to be mapped to the command
    // Third parameter is an array of middleware class names to be added to the stack
    $bus->dispatch('SomeCommand', [], []);

You can map the input data array of the Command's constructor with a plain list of arguments or the array itself. For example:

    // Send parameters in an array of input data ...    
    $bus->dispatch('SomeCommand', [
        'propertyOne'   => 'One',
        'propertyTwo'   => 'Two',
        'propertyThree' => 'Three',
    ], []);
    
    // ... and receive them as individual parameters ... 
    Class SomeCommand {
        public function __construct($propertyOne = 'A', $propertyTwo = 'B', $propertyThree = 'C'){
            //...
        }
    }
    
    // ... or receive array of input data itself 
        Class SomeCommand {
            public function __construct(array $data = [
                'propertyOne'   => 'A',
                'propertyTwo'   => 'B',
                'propertyThree' => 'C',
            ]){
                //...
            }
        }

Of course, you can use default values!

For more information about the usage of the tactician command bus please visit http://tactician.thephpleague.com/.

Example

Check out this example of the package implemented in a simple create order command https://gist.github.com/joselfonseca/24ee0e96666a06b16f92.

Bindings

You can configure the bindings for the locator, inflector, extractor and default bus by publishing the config file like so:

    php artisan vendor:publish

Then you can modify each class name and they will be resolved from the laravel container:

    return [
        // The locator to bind
        'locator' => 'Joselfonseca\LaravelTactician\Locator\LaravelLocator',
        // The inflector to bind
        'inflector' => 'League\Tactician\Handler\MethodNameInflector\HandleInflector',
        // The extractor to bind
        'extractor' => 'League\Tactician\Handler\CommandNameExtractor\ClassNameExtractor',
        // The bus to bind
        'bus' => 'Joselfonseca\LaravelTactician\Bus'
    ];

Generators

You can generate Commands and Handlers automatically using artisan:

artisan make:tactician:command Foo
artisan make:tactician:handler Foo

This will create FooCommand and FooHandler and place them in the app/Commands folder, please note that the words Command and Handler will be added to the class names respectively, so in the avobe example the clases created will be FooCommand and FooHandler.

To run both at once:

artisan make:tactician Foo

Middleware included

Laravel tactician includes some useful middleware you can use in your commands.

  • Database Transactions: This Middleware will run the command inside a database transaction, if any exception is thrown the transaction won't be committed and the database will stay intact, you can find this middleware in Joselfonseca\LaravelTactician\Middleware\DatabaseTransactions.

Change log

Please see the releases page https://github.com/joselfonseca/laravel-tactician/releases

Tests

To run the tests in this package, navigate to the root folder of the project and run:

    composer install

Then

    vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email jose at ditecnologia dot com instead of using the issue tracker.

Credits

License

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

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 1
  • Forks: 12
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-08-01