首页 > 怎么简单实现工作流?

怎么简单实现工作流?

最近一个项目需要实现工作流。我的想法是使用一些工作流引擎,但php平台上的工作流引擎很少,没什么成熟的案例。CTO也要我们自己实现。但现在我是眼前一抹黑,完全不知道怎么实现。能否请大家说说一个基本的工作流需要怎么实现?


可以看看php协程实现多任务协作,Generator,看看对你是否有帮助


随便写的,仅供参考

<?php
class process{

    const STATE_1   = 1;
    const STATE_2   = 2;
    const STATE_3   = 3;
    const STATE_4   = 4;
    const STATE_5   = 5;
    const STATE_ALL = 99;

    private $state     = null;
    private $statesLog = [];

    public function setState($state)
    {
        if (!$this->checkRoute($state)) {
            return false;
        }
        $this->state = $state;
        return true; 
    }

    protected function routes()
    {
        return [
            static::STATE_1=>[
                'id'      =>static::STATE_1,
                'name'    =>'状态1',
                'desc'    =>'状态1的描述',
                'to'      =>[static::STATE_3, static::STATE_4],
                'actions' =>[Actions::AC1, Actions::AC3],
                'hooks'   =>[...],
            ]
            ...
        ];
    }

}

class Actions{
    const AC1 = 1;
    const AC2 = 2;
    const AC3 = 3;

    public static function actions()
    {
        return [
            static::AC1 =>[
                'id'   =>static::AC1,
                'name' =>'AC1',
                'action'=>[
                    'do'    =>['nameSpace', 'className', 'methodName'],
                    'route' =>'/tools/sms/push',
                    'attr' =>['class'=>'hight_light warning'],
                ],
            ]
            ...
        ];
    }

    public static function getAction($actionId)
    {
        $actions = static::actions();
        return $actions[$actionId] ?? null;
    } 
}
【热门文章】
【热门文章】