gmorel/state-workflow-demo 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

gmorel/state-workflow-demo

Composer 安装命令:

composer create-project gmorel/state-workflow-demo

包简介

README 文档

README

Symfony 2

State Workflow Demo ===================

Helping you implementing a complex yet easily maintainable workflow.

Keywords : State Design Pattern, Workflow, Finite State Machine, Symfony2

A demonstration project for StateWorkflowBundle.

Demo Booking Workflow simple

Context

A Booking Entity being first incomplete, then waiting for payment, then paid then to delete or cancelled.

State declaration

The following States are all implementing BookingStateInterface

Default transitions - disabled

All available transitions are defined in BookingStateInterface

interface BookingStateInterface extends StateInterface
{
    public function setBookingAsWaitingForPayment(HasStateInterface $booking);
    public function setBookingAsPaid(HasStateInterface $booking);
    public function cancelBooking(HasStateInterface $booking);
    public function setBookingToBeDeleted(HasStateInterface $booking);
}

All States are implementing AbstractBookingState. Hence all transitions are disabled by default because of

throw $this->buildUnsupportedTransitionException(__METHOD__, $booking);

Enabled transitions

Transitions are enabled when a BookingStateInterface transition method is overridden.

public function setBookingAsPaid(HasStateInterface $booking)
{
    $newState = $this->getStateFromStateId(StatePaid::KEY, __METHOD__, $booking);
    if ($newState) {
        $booking->changeState($this->getStateWorkflow(), $newState);

        // Implement necessary relevant transition here
    }

    return $newState;
}

Inside these transition methods you can do what ever your want. And since each State is a service. You can inject whatever you want.

  • Log
  • Event Sourcing
  • Assertion
  • Send mail
  • etc..

Examples

Here is the generated Workflow Specification generated using the SpecGen command CLI sf spec-gen:state-workflow:generate-specifications :

Cytoscape generates the workflow layout randomly. If the layout doesn't suit well, refresh. Don't hesitate to drag and drop.

统计信息

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

GitHub 信息

  • Stars: 2
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2015-05-01