jildertmiedema/laravel-tactician

适用于laravel 8+的Tactician

V0.6.0 2024-01-19 10:47 UTC

This package is auto-updated.

Last update: 2024-09-22 17:06:42 UTC


README

laravel 5+的Tactician命令总线

Build Status Software License Packagist Version Total Downloads

安装

composer require jildertmiedema/laravel-tactician

JildertMiedema\LaravelTactician\TacticianServiceProvider 添加到你的 app.php 文件中

在命令行中运行以下命令

php artisan vendor:publish

编辑 config/tactician.php 并设置你的命名空间

用法

在你的控制器或控制台命令中,你可以使用特质 JildertMiedema\LaravelTactician\DispatchesCommands

use YourApp\Commmands\DoSomethingCommand;
use Illuminate\Routing\Controller as BaseController;
use JildertMiedema\LaravelTactician\DispatchesCommands;

class Controller extends BaseController
{
    use DispatchesCommands;

    public function store(Request $request)
    {
        $command = new DoSomethingCommand($request->get('id'), $request->get('value'));
        $this->dispatch($command);

        return redirect('/');
    }
}

扩展

中间件

在你的自己的 ServiceProvider 中

$this->app['tactician.middleware']->prepend('your.middleware');

$this->app->bind('your.middleware', function () {
    return new MiddleWare
});

定位器

默认定位器由 tactician.handler.locator 在容器中设置,当然你也可以更改它。

在你的自己的 ServiceProvider 中

$this->bind('tactician.handler.locator', function () {
    return new YourLocator();
});