gmorel / state-workflow-demo
Installs: 14
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 3
Forks: 0
Open Issues: 0
Type:project
Requires
- php: >=5.3.3
- doctrine/dbal: <2.5
- doctrine/doctrine-bundle: ~1.2
- doctrine/orm: ~2.2,>=2.2.3,<2.5
- gmorel/state-workflow-bundle: dev-master
- incenteev/composer-parameter-handler: ~2.0
- sensio/distribution-bundle: ~3.0,>=3.0.12
- sensio/framework-extra-bundle: ~3.0,>=3.0.2
- spec-gen/state-workflow-spec-gen-bundle: dev-master
- symfony/assetic-bundle: ~2.3
- symfony/monolog-bundle: ~2.4
- symfony/swiftmailer-bundle: ~2.3
- symfony/symfony: 2.6.*
- twig/extensions: ~1.0
Requires (Dev)
- phpunit/phpunit: ~4
- sensio/generator-bundle: ~2.3
This package is not auto-updated.
Last update: 2024-10-30 10:15:27 UTC
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.