PHP code example of madong / workflow

1. Go to this page and download the library: Download madong/workflow library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

madong / workflow example snippets


use madong\workflow\Engine;
use madong\workflow\config\EngineConfig;
use madong\workflow\interface\services\{
    IProcessDefineService,
    IProcessInstanceService,
    IProcessTaskService,
};

// 1. 创建引擎
$engine = new Engine(new EngineConfig(
    services: [
        IProcessDefineService::class   => \App\Service\ProcessDefineService::class,
        IProcessInstanceService::class => \App\Service\ProcessInstanceService::class,
        IProcessTaskService::class     => \App\Service\ProcessTaskService::class,
    ],
    debug: true,
));

// 2. 发布流程定义
$defineService = $engine->getService(IProcessDefineService::class);
$defineService->createProcessDefine([
    'id'      => 'leave_001',
    'name'    => 'wf-leave',
    'content' => $jsonContent, // 流程定义 json 字符串
]);

// 3. 启动流程
$instance = $engine->startProcess('leave_001', 'user001', ['f_day' => 3]);

// 4. 完成任务
$taskService = $engine->getService(IProcessTaskService::class);
$tasks = $taskService->getDoingTaskList($instance->getId(), '');
$engine->completeTask($tasks[0]->getId(), 'user001', ['approved' => true]);