2017 © Pedro Peláez
 

project state-workflow-demo

image

gmorel/state-workflow-demo

  • Sunday, September 13, 2015
  • by gmorel
  • Repository
  • 2 Watchers
  • 2 Stars
  • 14 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Symfony 2, (*1)

State Workflow Demo

Helping you implementing a complex yet easily maintainable workflow.

Keywords : State Design Pattern, Workflow, Finite State Machine, Symfony2, (*2)

A demonstration project for StateWorkflowBundle., (*3)

Demo Booking Workflow simple, (*4)

Context

A Booking Entity being first incomplete, then waiting for payment, then paid then to delete or cancelled. - State : BookingStateInterface instance - Transition : BookingStateInterface method, (*5)

State declaration

The following States are all implementing BookingStateInterface - StateIncomplete - StateCancelled - StateWaitingPayment - StatePaid - StateToDelete, (*6)

Default transitions - disabled

All available transitions are defined in BookingStateInterface, (*7)

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, (*8)

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

Enabled transitions

Transitions are enabled when a BookingStateInterface transition method is overridden., (*9)

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.., (*10)

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, (*11)

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

The Versions