A PHP package for managing state transitions

1.0.2 2019-01-24 08:49 UTC

This package is auto-updated.

Last update: 2024-02-24 20:37:44 UTC


A PHP package for dealing with state transitions.

Latest Stable Version Total Downloads Scrutinizer Code Quality Code Coverage Build Status

State transitions are a good way to manage lifecycles and pipelines on applications, as for example:

  • Order and payment status on an e-commerce
  • Invoice Status on a finance system
  • Ticket Status on ticket service desk system
  • Sales status on a CRM


The workflow package can be installed via Composer by requiring the davispeixoto/workflow package in your project's composer.json.

    "require": {
        "davispeixoto/workflow": "~1.0"


$ php composer.phar require davispeixoto/workflow

And running a composer update from your terminal:

php composer.phar update


To use it, first you need to create the status you are going to use for representing your states.

use MyCLabs\Enum\Enum;

class SalesStates extends Enum
    public const NEW = 'new';
    public const DEALING = 'dealing';
    public const WON = 'won';
    public const LOST = 'lost';

Then you can create your workflow based on valid transitions

use Davispeixoto\WorkflowInterface\Transition;
use Davispeixoto\WorkflowInterface\WorkflowInterface;

class SalesWorkflow extends WorkflowInterface
    public function __construct(SalesStates $initialStatus)

        // setup the transitions
        $transitions = [];

        $transitions[] = new Transition(
            new SalesStates(SalesStates::NEW),
            new SalesStates(SalesStates::DEALING)

        $transitions[] = new Transition(
            new SalesStates(SalesStates::DEALING),
            new SalesStates(SalesStates::WON)

        $transitions[] = new Transition(
            new SalesStates(SalesStates::DEALING),
            new SalesStates(SalesStates::LOST)

        $this->allowedTransitions = $transitions;

        // setup the finished status, if any/needed
        $finished = [];

        $finished[] = new SalesStates(SalesStates::WON);
        $finished[] = new SalesStates(SalesStates::LOST);

        $this->finishedStatus = $finished;

Now you can use this workflow to manage state transitions on you applications.


This software is licensed under the MIT license


This project follows the Semantic Versioning


For all PHP community