Home  >  Article  >  Backend Development  >  怎么简单实现工作流?

怎么简单实现工作流?

PHP中文网
PHP中文网Original
2017-03-24 10:27:473334browse

最近一个项目需要实现工作流。我的想法是使用一些工作流引擎,但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=>[
               &#39;id&#39;      =>static::STATE_1,
               &#39;name&#39;    =>&#39;状态1&#39;,
               &#39;desc&#39;    =>&#39;状态1的描述&#39;,
               &#39;to&#39;      =>[static::STATE_3, static::STATE_4],
               &#39;actions&#39; =>[Actions::AC1, Actions::AC3],
               &#39;hooks&#39;   =>[...],
           ]
           ...
       ];
   }

}

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

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

   public static function getAction($actionId)
   {
       $actions = static::actions();
       return $actions[$actionId] ?? null;
   } 
}

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

相关文章:

PHP 工作流 自定义表单解决方案

介绍一个真正符合中国国情的工作流设计参考(包括PHP实现)

通达OA2015版工作流插件和列表控件数据解析

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn