最近一个项目需要实现工作流。我的想法是使用一些工作流引擎,但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协程实现多任务协作,generator,看看对你是否有帮助
相关文章:
php 工作流 自定义表单解决方案
介绍一个真正符合中国国情的工作流设计参考(包括php实现)
通达oa2015版工作流插件和列表控件数据解析