承接 kitpages/workflow-bundle 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kitpages/workflow-bundle

Composer 安装命令:

composer require kitpages/workflow-bundle

包简介

This is a Symfony2 bundle that provides a workflow system.

关键字:

README 文档

README

Build Status

This bundle provides a generic workflow system.

It is used in production on a specific project, but it must be considered as an beta version.

Use case

Imagine you manage (technically) 3 different newspapers : "NYC news", "Paris news" and "Grenoble news".

  • For NYC news, an article has to be validated by the editor in chief only (and rewritten by the author until the editor says yes). Then it should be integrated to the printing process.
  • For Paris news, an article is firstly validated by a secretary, then by a pair (another author from the same domain) and the editor. Then it should be integrated to the printing process.
  • For Grenoble news : This is only an online newspaper. No validation, but it can be unpublished by the editor later

You can build a single, coherent code that can manage these 3 different buisiness processes. You can do that through a workflow system. Each newspaper process is represented by a workflow configuration file.

This bundle provides a generic workflow system build to represent any business process.

Quick start

  • add default step in config.yml
kitpages_workflow:
    default_step_name: workflow.default

kitpages_step:
    shared_step_list:
        workflow.default:
            help:
                short: "Default step"
                complete: |
                    This step always return default value
            class: Kitpages\WorkflowBundle\Step\DefaultStep
  • using
        // create workflow configuration
        $config='
workflow_definition:
    name: hello_world
    init_state: start_state
    state_list:
        start_state:
            event_list:
                goto_end:
                    step:
                        name: workflow.default
                    next_state:
                        default: end_state
                cancel:
                    next_state: start_state
        end_state:
            event_list:
                goto_start:
                    next_state: start_state
        ';

        // get workflow manager
        $workflowManager = $this->get("workflow.manager");

        // create workflow
        $workflowConfiguration = YamlWorkflowConfigurationParser::parse($config);
        $workflow = $workflowManager->createWorkflow("hello_world_instance_workflow", $workflowConfiguration);

        // dispatch event
        $dispatcher = $this->get('event_dispatcher');
        $actionEvent = new ActionEvent("goto_end");
        $dispatcher->dispatch(KitpagesWorkflowEvents::ACTION_EVENT, $actionEvent);

        // test workflow
        $this->assertEquals ( "end_state", $workflow->getCurrentState() );

        // back to start
        $dispatcher->dispatch(KitpagesWorkflowEvents::ACTION_EVENT, new ActionEvent("goto_start"));
        $this->assertEquals ( "start_state", $workflow->getCurrentState() );

State of the bundle

  • beta state
  • partially tested (60%)
  • under travis-ci

Installation

Add KitpagesWorkflowBundle in your composer.json

{
    "require": {
        "kitpages/workflow-bundle": "~1.0"
    }
}

Now tell composer to download the bundle by running:

$ php composer.phar update kitpages/workflow-bundle

AppKernel.php

$bundles = array(
    ...
    new Kitpages\StepBundle\KitpagesStepBundle(),
    new Kitpages\WorkflowBundle\KitpagesWorkflowBundle(),
);

Very minimal configuration in config.yml

imports:
    - { resource: @KitpagesWorkflowBundle/Resources/config/steps.yml }

kitpages_workflow:
    default_step_name: workflow.default

Principles

General mecanism

  • This bundle is used to manage a state machine
  • The configuration of the workflow is defined in a WorkflowConfiguration object
  • The current instance of a machine state is in a Workflow object
  • A workflow manager keep references of every workflow, listen for ActionEvents, run steps, change workflow states,...
  • A step contains the operations to do after the reception of an ActionEvent. Then the returned value allows to decide the next workflow state according to the configuration.
  • Every workflow state listen for some ActionEvent

Everything is done in steps

Steps are classes that does something. Steps are documented in the project on github : KitpagesStepBundle.

We are using steps that extends the AbstractWorkflowStep that add a reference to the current workflow and the actionEvent.

Example of step :

Configuration

kitpages_step:
    shared_step_list:
        my_step:
            help:
                short: "short description of my step"
                complete: |
                    Longer description
            class: Kitpages\MyBundle\Step\MyStep
            parameter_list:
                url: test.mydomain.com
            service_list:
                logger: logger

Code of the step

use Kitpages\StepBundle\Step\StepEvent;
use Kitpages\WorkflowBundle\Step\AbstractWorkflowStep;

class MyStep extends AbstractWorkflowStep {

    public function execute(StepEvent $event = null)
    {
        // get current workflow and action event
        $workflow = $this->getWorkflow();
        $actionEvent = $this->getActionEvent();

        // extract data from actionEvent
        $myValue1 = $actionEvent->get("myKey");
        $myOtherValue = $actionEvent->get("myOtherKey");

        // do someting
        $logger = $this->getService("logger");
        $logger->info("I write a log");
        $urlStepParameter = $this->getParameter("url");


        // record some values in the workflow object
        $workflow->set("resultKey", "value calculated");

        if ($someResult == true) {
            return "ok";
        } else {
            return "false";
        }
    }
}

More advanced Features

TODO : features to document

  • workflow parameters
  • sub workflow
  • workflow events and step events
  • workflow configuration shortcuts
  • workflow persistance
  • serveral workflows in parallel

Versions

  • 2014/04/24 : v1.0.0 - first stable release

Roadmap

Backward compatibility is maintained for version 1.x.

By 2014/06

  • more tests and docs
  • yaml parser in service (static call will remain but deprecated)
  • pre-generation and cache for the proxy system

Later :

  • a convivial debug interface

kitpages/workflow-bundle 适用场景与选型建议

kitpages/workflow-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 541 次下载、GitHub Stars 达 5, 最近一次更新时间为 2014 年 04 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「workflow」 「step」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 kitpages/workflow-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 kitpages/workflow-bundle 我们能提供哪些服务?
定制开发 / 二次开发

基于 kitpages/workflow-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 541
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 9
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 6
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-04-16