PHPackages                             lexik/workflow-bundle - 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. [Framework](/categories/framework)
4. /
5. lexik/workflow-bundle

Abandoned → [symfony/workflow](/?search=symfony%2Fworkflow)ArchivedSymfony-bundle[Framework](/categories/framework)

lexik/workflow-bundle
=====================

Simple workflow bundle for Symfony2

v0.5.0(10y ago)130105.2k↓30%29[8 issues](https://github.com/lexik/LexikWorkflowBundle/issues)MITPHPPHP &gt;=5.3.3

Since Nov 26Pushed 5y ago23 watchersCompare

[ Source](https://github.com/lexik/LexikWorkflowBundle)[ Packagist](https://packagist.org/packages/lexik/workflow-bundle)[ Docs](https://github.com/lexik/LexikWorkflowBundle)[ RSS](/packages/lexik-workflow-bundle/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

LexikWorkflowBundle
===================

[](#lexikworkflowbundle)

[![Build Status](https://camo.githubusercontent.com/51c878311a13218178ed79e31d91e04157e413f72a05a266bf6fa6c67f9737eb/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f6c6578696b2f4c6578696b576f726b666c6f7742756e646c652e706e67)](http://travis-ci.org/lexik/LexikWorkflowBundle)[![Latest Stable Version](https://camo.githubusercontent.com/e217c94cc80f77f1d32ef23fdaeb760d3c5e16d92c04ef8390e89c382a0604cc/68747470733a2f2f706f7365722e707567782e6f72672f6c6578696b2f776f726b666c6f772d62756e646c652f762f737461626c65)](https://packagist.org/packages/lexik/workflow-bundle)[![SensioLabsInsight](https://camo.githubusercontent.com/bd5615b60a5ee4e488cabce5bf04fb3ab276d5cf88e68aa69c360fa2c4a4144d/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f37323039643534322d343434382d343834342d383338632d3465353331353165633736392f6d696e692e706e67)](https://insight.sensiolabs.com/projects/7209d542-4448-4844-838c-4e53151ec769)

This bundle is deprecated
=========================

[](#this-bundle-is-deprecated)

This Symfony2 bundle allows to define and manage simple workflows using the event dispatcher for actions and validations.

This bundle was originally a fork of [FreeAgentWorkflowBundle](https://github.com/jeremyFreeAgent/FreeAgentWorkflowBundle). The implementation differs in the way that we use event dispatcher and we store steps history for each model object.

Installation
------------

[](#installation)

Installation with composer:

```
    ...
    "require": {
        ...
        "lexik/workflow-bundle": "dev-master",
        ...
    },
    ...
```

Next, be sure to enable the bundle in your `app/AppKernel.php` file:

```
public function registerBundles()
{
    return array(
        // ...
        new Lexik\Bundle\WorkflowBundle\LexikWorkflowBundle(),
        // ...
    );
}
```

How it works
============

[](#how-it-works)

First of all, what's a workflow? According to wikipedia definition, "a workflow consists of a sequence of connected steps". You can see below the workflow terms used by the bundle:

- to define your workflow you will have to describe some processes ;
- a process is defined by a series of steps, and you advance through the process step by step ;
- a step contains validations and actions, validations are executed when you try to reach the step, if those validations are successful the step has been reached and actions are executed.

The workflow works on a "model" object, a model is a class that implements `Lexik\Bundle\WorkflowBundle\Model\ModelInterface`. Each time a model tries to reach a step, we log it in the database to keep the steps history.

Workflow example
----------------

[](#workflow-example)

Let's define a simple workflow around a post from its creation to its publication:

- first, we have to create a draft, then an admin must validate this draft before it can be published ;
- once a post is published, any user can unpublish it ;
- if a post is not published, an admin can delete it ;
- if the publication step fails, we go back to the draft step.

```
# app/config/config.yml
lexik_workflow:
    processes:
        post_publication:
            start: draft_created
            end:   [ deleted ]
            steps:
                draft_created:
                    label: "Draft created"
                    roles: [ ROLE_USER ]
                    model_status: [ setStatus, Project\Bundle\SuperBundle\Entity\Post::STATUS_DRAFT ]
                    next_states:
                        validate: { type: step, target: validated_by_admin } # you can omit "type: step" as "step" is the default value of the "type" node. Soon, you'll be able to use "type: process".

                validated_by_admin:
                    label: "Post validated"
                    roles: [ ROLE_ADMIN ]
                    model_status: [ setStatus, Project\Bundle\SuperBundle\Entity\Post::STATUS_VALIDATED ]
                    next_states:
                        publish: { target: published }

                published:
                    label: "Post published"
                    roles: [ ROLE_USER ]
                    model_status: [ setStatus, Project\Bundle\SuperBundle\Entity\Post::STATUS_PUBLISHED ]
                    on_invalid: draft_created # will try to reach the "draft_created" step in case validations to reach "published" fail.
                    next_states:
                        unpublish: { target: unpublished }

                unpublished:
                    label: "Post unpublished"
                    roles: [ ROLE_USER ]
                    model_status: [ setStatus, Project\Bundle\SuperBundle\Entity\Post::STATUS_UNPUBLISHED ]
                    next_states:
                        delete:  { target: deleted }
                        publish: { target: published }

                deleted:
                    label: "Post deleted"
                    roles: [ ROLE_ADMIN ]
                    model_status: [ setStatus, Project\Bundle\SuperBundle\Entity\Post::STATUS_DELETED ]
                    next_states: ~
```

Model object
------------

[](#model-object)

The workflow handles "model" objects. A "model" object is basically an instance of `Lexik\Bundle\WorkflowBundle\Model\ModelInterface`. This interface has 3 methods to implement:

- `getWorkflowIdentifier()` returns an unique identifier used to store a model state in the database ;
- `getWorkflowData()` returns an array of data to store with the model state ;
- `getWorkflowObject()` returns the final object, it will be passed to the security context by the default ProcessHandler.

Here's an example of a `PostModel` class we could use in the `post_publication` process:

```
