PHPackages                             gmorel/state-workflow-demo - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. gmorel/state-workflow-demo

ActiveProject

gmorel/state-workflow-demo
==========================

214PHP

Since Aug 6Pushed 10y ago2 watchersCompare

[ Source](https://github.com/gmorel/StateWorkflowDemo)[ Packagist](https://packagist.org/packages/gmorel/state-workflow-demo)[ RSS](/packages/gmorel-state-workflow-demo/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (2)Used By (0)

[![Symfony 2](https://raw.githubusercontent.com/spec-gen/state-workflow-spec-gen-bundle/master/doc/symfony.png)](https://raw.githubusercontent.com/spec-gen/state-workflow-spec-gen-bundle/master/doc/symfony.png)

State Workflow Demo =================== Helping you implementing a complex yet easily maintainable workflow.
--------------------------------------------------------------------

[](#helping-you-implementing-a-complex-yet-easily-maintainable-workflow)

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

A `demonstration` project for [StateWorkflowBundle](https://github.com/gmorel/StateWorkflowBundle).

[![Demo Booking Workflow simple](https://raw.githubusercontent.com/spec-gen/state-workflow-spec-gen-bundle/master/doc/demo-booking-workflow.png "Demo Booking Workflow simple")](https://raw.githubusercontent.com/spec-gen/state-workflow-spec-gen-bundle/master/doc/demo-booking-workflow.png)

### Context

[](#context)

A [Booking Entity](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/Entity/Booking.php)being first `incomplete`, then `waiting for payment`, then `paid` then `to delete` or `cancelled`.

- **State** : [BookingStateInterface](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/BookingStateInterface.php) instance
- **Transition** : [BookingStateInterface](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/BookingStateInterface.php) method

### State declaration

[](#state-declaration)

The following States are all implementing [BookingStateInterface](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/BookingStateInterface.php)

- [StateIncomplete](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/Implementation/StateIncomplete.php)
- [StateCancelled](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/Implementation/StateCancelled.php)
- [StateWaitingPayment](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/Implementation/StateWaitingPayment.php)
- [StatePaid](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/Implementation/StatePaid.php)
- [StateToDelete](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/Implementation/StateToDelete.php)

### Default transitions - disabled

[](#default-transitions---disabled)

All available transitions are defined in [BookingStateInterface](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/BookingStateInterface.php)

```
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](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/AbstractBookingState.php). Hence all `transitions` are disabled by default because of

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

### Enabled transitions

[](#enabled-transitions)

Transitions are enabled when a [BookingStateInterface](https://github.com/gmorel/StateWorkflowDemo/blob/master/src/BookingEngine/Domain/State/BookingStateInterface.php)`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

[](#examples)

Here is the generated Workflow Specification generated using the [SpecGen](https://github.com/spec-gen/state-workflow-spec-gen-bundle) command CLI `sf spec-gen:state-workflow:generate-specifications` :

- Simple workflow [demo.booking\_engine.state\_workflow.html](http://rawgit.com/gmorel/StateWorkflowDemo/master/specification/workflow/demo.booking_engine.state_workflow.html)
- More complex workflow [demo.quote\_engine.state\_workflow.html](http://rawgit.com/gmorel/StateWorkflowDemo/master/specification/workflow/demo.quote_engine.state_workflow.html)

[Cytoscape](http://www.cytoscape.org) generates the workflow layout randomly. If the layout doesn't suit well, refresh. Don't hesitate to drag and drop.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/fbc794e47ef6d26ce929e38e924645e421d3602021924f9c366b175ac829e5bc?d=identicon)[gmorel](/maintainers/gmorel)

---

Top Contributors

[![gmorel](https://avatars.githubusercontent.com/u/2279794?v=4)](https://github.com/gmorel "gmorel (1 commits)")

### Embed Badge

![Health badge](/badges/gmorel-state-workflow-demo/health.svg)

```
[![Health](https://phpackages.com/badges/gmorel-state-workflow-demo/health.svg)](https://phpackages.com/packages/gmorel-state-workflow-demo)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
