Download the PHP package tyhand/workflow-bundle without Composer
On this page you can find all versions of the php package tyhand/workflow-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package workflow-bundle
Workflow Bundle
A simple experimental Symfony bundle built to help manage some of our application workflows. Don't know if I like the end result, but here it is.
Requirements
Symfony 2.3 or higher and Doctrine 2.2 or higher.
Installation
To install with composer, add the bundle to your composer json.
Next register the bundle with the AppKernel.
Usage
Making a workflow instance
To make an entity be able to be used as a workflow instance, you need to implement the context interface in the entity class.
After that the methods in the interface will need to be implemented, or you can add the TyHand\WorkflowBundle\Workflow\Context\ContextTrait trait to the entity to implement all the methods in the interface. With the interface added and the methods implemented or the trait added, run the doctrine schema commands to add the workflow tables. Dumping the SQL should show tables for the workflow context and many-to-many tables for each entity that implements the context interface.
Once the dumped SQL is verified, update the schema either through a forced update or a database migration.
Creating a workflow
Start a new workflow by creating a new workflow definition class that extends the abstract workflow definition provided by the bundle.
The abstract workflow definition has three methods that are abstract that will need to be implemented. First is getName() which just returns a name for the workflow. This name should be unique in the scope of the application. The second method is getContextClass() which returns the name of the class that is the context of the workflow.
The third required method is the build method which is the meat of the workflow definition. This method will receive and return a workflow builder that specifies the structure of the workflow.
The main part of the workflow are the states. States each have a unique name (in the scope of the workflow), a set of exit conditions, and an optional set of actions. If a state has no exit conditions then it is considered a terminal state, and once a workflow instance reaches this point, it is no longer considered active. Actions are methods that can be called when an instance enters a workflow. The exit conditions can either be an event that can be fired elsewhere in the application, a conditional statement that is evaluated upon an instance entering the state, and a time limit that moves to a given state if an instance has been in the state for so long. Note: to use the time limit condition, a cron job or something similar will need to run the app/console check time limit command ('tyhand_workflow:states:check_time_limit') at set intervals or your choosing.
Example:
To make state actions and conditions more useful, just inject various services into the workflow definition and add them to the conditions or action function. For example, let's say we want to throw an event at the end of the workflow, then just add an action kind of like this to your terminal state.
Make a the workflow manager aware of the definition class by making it a service and adding the 'tyhand_workflow.definition' tag. Example:
Placing instance into a workflow
Put a context into a workflow by using the workflow manager service.
Workflow events
Trigger the event transtions by throwing a workflow event with context, workflow name, and event name.
Testing
PHPUnit is used for testing the bundle. Create a phpunit.xml from the phpunit.xml.dist file located in the root of the bundle, and then run phpunit to test.
License
This bundle is under the MIT License
All versions of workflow-bundle with dependencies
doctrine/orm Version >=2.2.3
doctrine/doctrine-bundle Version 1.2.*