php - 怎么简单实现工作流?
本文介绍了php - 怎么简单实现工作流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
问 题
最近一个项目需要实现工作流。我的想法是使用一些工作流引擎,但php平台上的工作流引擎很少,没什么成熟的案例。CTO也要我们自己实现。但现在我是眼前一抹黑,完全不知道怎么实现。能否请大家说说一个基本的工作流需要怎么实现?
解决方案
随便写的,仅供参考
<?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;
}
}
这篇关于php - 怎么简单实现工作流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文