gmorel/state-workflow-demo
Composer 安装命令:
composer create-project gmorel/state-workflow-demo
包简介
README 文档
README
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.
Context
A Booking Entity
being first incomplete, then waiting for payment, then paid then to delete or cancelled.
- State : BookingStateInterface instance
- Transition : BookingStateInterface method
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 :
- Simple workflow demo.booking_engine.state_workflow.html
- More complex workflow demo.quote_engine.state_workflow.html
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
其他信息
- 授权协议: proprietary
- 更新时间: 2015-05-01

