This post is ready for review.
+ {% endif %} + + {# Check if some place has been marked on the object #} + {% if 'waiting_some_approval' in workflow_marked_places(post) %} + PENDING + {% endif %} + +Learn more +---------- .. toctree:: :maxdepth: 1 - :glob: - - workflow/* -.. _Petri nets: https://en.wikipedia.org/wiki/Petri_net + workflow/introduction + workflow/dumping-workflows diff --git a/workflow/state-machines.rst b/workflow/introduction.rst similarity index 74% rename from workflow/state-machines.rst rename to workflow/introduction.rst index e1cb97e62b0..4836a39d2ec 100644 --- a/workflow/state-machines.rst +++ b/workflow/introduction.rst @@ -1,18 +1,62 @@ -.. index:: - single: Workflow; Workflows as State Machines +Workflows and State Machines +============================ -Workflows as State Machines -=========================== +Worflows +-------- -The workflow component is modelled after a *Workflow net* which is a subclass -of a `Petri net`_. By adding further restrictions you can get a state machine. -The most important one being that a state machine cannot be in more than -one place simultaneously. It is also worth noting that a workflow does not -commonly have cyclic path in the definition graph, but it is common for a state -machine. +A workflow is a model of a process in your application. It may be the process of +how a blog post goes from draft to review and publish. Another example is when a +user submits a series of different forms to complete a task. Such processes are +best kept away from your models and should be defined in configuration. -Example of a State Machine --------------------------- +A **definition** of a workflow consist of places and actions to get from one +place to another. The actions are called **transitions**. A workflow does also +need to know each object's position in the workflow. That **marking store** +writes to a property of the object to remember the current place. + +.. note:: + + The terminology above is commonly used when discussing workflows and + `Petri nets`_ + +Examples +~~~~~~~~ + +The simplest workflow looks like this. It contains two places and one transition. + +.. image:: /_images/components/workflow/simple.png + +Workflows could be more complicated when they describe a real business case. The +workflow below describes the process to fill in a job application. + +.. image:: /_images/components/workflow/job_application.png + +When you fill in a job application in this example there are 4 to 7 steps +depending on the what job you are applying for. Some jobs require personality +tests, logic tests and/or formal requirements to be answered by the user. Some +jobs don't. The ``GuardEvent`` is used to decide what next steps are allowed for +a specific application. + +By defining a workflow like this, there is an overview how the process looks +like. The process logic is not mixed with the controllers, models or view. The +order of the steps can be changed by changing the configuration only. + +State Machines +-------------- + +A state machine is a subset of a workflow and its purpose is to hold a state of +your model. The most important differences between them are: + +* Workflows can be in more than one place at the same time, whereas state + machines can't; +* Workflows usually don't have cyclic paths in the definition graph, but it's + common for state machines; +* In order to apply a transition, worflows require that the object is in all the + previous places of the transition, whereas state machines only require that + the object is at least in one of those places. + +Example +~~~~~~~ A pull request starts in an initial "start" state, a state for e.g. running tests on Travis. When this is finished, the pull request is in the "review" @@ -190,8 +234,9 @@ Below is the configuration for the pull request state machine. ], ]); -You can now use this state machine by getting the ``state_machine.pull_request`` service:: +You can now use this state machine by getting the ``state_machine.pull_request`` +service:: $stateMachine = $this->container->get('state_machine.pull_request'); -.. _Petri net: https://en.wikipedia.org/wiki/Petri_net +.. _`Petri nets`: https://en.wikipedia.org/wiki/Petri_net diff --git a/workflow/usage.rst b/workflow/usage.rst deleted file mode 100644 index e8f1268dc14..00000000000 --- a/workflow/usage.rst +++ /dev/null @@ -1,486 +0,0 @@ -.. index:: - single: Workflow; Usage - -How to Use the Workflow -======================= - -A workflow is a process or a lifecycle that your objects go through. Each -step or stage in the process is called a *place*. You do also define *transitions* -to that describes the action to get from one place to another. - -.. image:: /_images/components/workflow/states_transitions.png - -A set of places and transitions creates a **definition**. A workflow needs -a ``Definition`` and a way to write the states to the objects (i.e. an -instance of a :class:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface`.) - -Consider the following example for a blog post. A post can have these places: -``draft``, ``reviewed``, ``rejected``, ``published``. You can define the workflow -like this: - -.. configuration-block:: - - .. code-block:: yaml - - # app/config/config.yml - framework: - workflows: - blog_publishing: - type: 'workflow' # or 'state_machine' - audit_trail: - enabled: true - marking_store: - type: 'multiple_state' # or 'single_state' - arguments: - - 'currentPlace' - supports: - - AppBundle\Entity\BlogPost - initial_place: draft - places: - - draft - - reviewed - - rejected - - published - transitions: - to_review: - from: draft - to: reviewed - publish: - from: reviewed - to: published - reject: - from: reviewed - to: rejected - - .. code-block:: xml - - - -This post is ready for review.
- {% endif %} - - {# Check if some place has been marked on the object #} - {% if 'waiting_some_approval' in workflow_marked_places(post) %} - PENDING - {% endif %}Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: