PHP code example of busyphp / workflow

1. Go to this page and download the library: Download busyphp/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/ */

    

busyphp / workflow example snippets


namespace core\model\test;

#[\BusyPHP\workflow\annotation\StateMachine(
    // 状态字段名称
    field: 'status',
    
    // 模型支持的状态集合
    places: ['待审核', '待发布', '已发布', '已下架', '已取消'],
    
    // 状态转换过程配置
    transitions: [
        // 审核操作
        'examine' => [
            'from' => '待审核',
            'to' => '待发布'
        ],
        
        // 发布操作
        'publish' => [
            'from' => '待发布',
            'to' => '已发布'
        ],
        
        // 下架操作
        'revoke' => [
            'from' => '已发布',
            'to' => '已下架'
        ],
        
        // 取消操作
        'cancel' => [
            'form' => ['待审核', '待发布', '已发布', '已下架'],
            'to' => '已取消'
        ]
    ],
    
    // 初始状态
    initial: '待审核'
)]
class Test extends \BusyPHP\Model {
    // 绑定模型字段类即可自动为模型字段类添加虚拟属性
    // 指示是否可以进行对应的操作:
    // $field->canExamine bool
    // $field->canPublish bool
    // $field->canRevoke bool
    // $field->canCancel boll
    protected string $fieldClass = TestField::class;
}

class TestField extends \BusyPHP\model\Field {
    
}