承接 nowi5/laravel-workflow 相关项目开发

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

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

nowi5/laravel-workflow

最新稳定版本:0.0.2

Composer 安装命令:

composer require nowi5/laravel-workflow

包简介

Workflow Engine for Laravel

README 文档

README

The Laravel Workflow Jobs package allows you to effortlessly create workflows that run as jobs with robust logging capabilities. Use this package to design, execute, and monitor workflow processes using Laravel jobs and enjoy a seamless experience with dynamic parameter passing and custom logic evaluations.

Installation

  1. Install the package via composer:

    composer require laravel-workflow-jobs-package
    
  2. Publish the config file:

    php artisan vendor:publish --provider="Workflow\WorkflowServiceProvider"
    
  3. Run migrations (if needed) to set up the required tables for logging and management:

    php artisan migrate
    

Usage

Creating a Workflow

To create a workflow, you can define it as shown in the example:

namespace  App\Workflow;

use App\Jobs\WorkflowStepJob;
use Workflow\Workflow;

class ExampleWorkflow extends Workflow {

    public $name = "TestWorkflow";
    public $version = "1.0.0";

    public function execute(){
        // Adding steps to the workflow
        $this->addStep("step1", WorkflowStepJob::class, ["param1" => "some value"]);

        // Setting the logic for the workflow
        $this->addLogic("step1", "step2");
    }
}

Running a Workflow

After defining your workflow, you can start and fetch its JSON representation:

$workflow = new ExampleWorkflow();
$workflow->start("Hello Test");
$workflowjson = $workflow->getJson();
return response("<pre><code>".$workflowjson."</code></pre>", 200);

Creating a Workflow Step (Job)

Each step in a workflow corresponds to a Laravel job. To create a custom workflow job:

namespace App\Jobs;

use Workflow\Jobs\WorkflowJob;

class WorkflowStepJob extends WorkflowJob {

    public $name = "Example Step Name"; // Keep this unique
    public $version = "1.0.0";

    public function execute() {
        $content = "Hello Custom Workflow, " . now() . "\n";
        return ['content' => $content];
    }
}

Dynamic Parameter Passing

You can pass parameters from one step's output to another's input dynamically using the format %stepName.parameterName%:

$this->addStep("step2", WorkflowStepJob::class, ["param1" => "%step1.randomNumber%"]);

Custom Logic Evaluation

You can also define custom logic evaluations to determine which step to execute next based on the output of the previous steps: Defining own logic for the workflow as well as adding logic at all is optional. If no logic is defined, the workflow will execute all steps in the order they were added.

$this->addLogic("step3", null, [
["evaluate" => "%step2.outputParameterName%", "comparison" => "<50", "next" => "step5"],
["evaluate" => "%step2.outputParameterName%", "comparison" => ">=50", "next" => "step4"]
]);

Contributing

If you'd like to contribute to this project, please submit a PR or open an issue. We appreciate any feedback or improvements!

License

This package is open-source software licensed under the MIT license.

Notes

"Laravel" is a registered trademark of Taylor Otwell. This project is not affiliated, associated, endorsed, or sponsored by Taylor Otwell, nor has it been reviewed, tested, or certified by Taylor Otwell. The use of the trademark "Laravel" is for informational and descriptive purposes only. Laravel Workflow is not officially related to the Laravel trademark or Taylor Otwell.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-08-07