Skip to content

[Workflow] rearrange how workflow events are presented #8059

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 22, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 50 additions & 31 deletions workflow/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ like this:
The marking store type could be "multiple_state" or "single_state".
A single state marking store does not support a model being on multiple places
at the same time.

.. tip::

The ``type`` (default value ``single_state``) and ``arguments`` (default value ``marking``)
Expand Down Expand Up @@ -189,49 +189,68 @@ Each step has three events that are fired in order:
* An event for the workflow concerned;
* An event for the workflow concerned with the specific transition or place name.

The following events are dispatched:
When a state transition is initiated, the events are dispatched in the following
order:

* ``workflow.guard``
* ``workflow.[workflow name].guard``
* ``workflow.[workflow name].guard.[transition name]``
``workflow.guard``
Validate whether the transition is allowed at all (:ref:`see below <workflow-usage-guard-events>`).

The three events being dispatched are:

* ``workflow.guard``
* ``workflow.[workflow name].guard``
* ``workflow.[workflow name].guard.[transition name]``

``workflow.leave``
The object is about to leave a place.

The three events being dispatched are:

* ``workflow.leave``
* ``workflow.[workflow name].leave``
* ``workflow.[workflow name].leave.[place name]``
* ``workflow.leave``
* ``workflow.[workflow name].leave``
* ``workflow.[workflow name].leave.[place name]``

* ``workflow.transition``
* ``workflow.[workflow name].transition``
* ``workflow.[workflow name].transition.[transition name]``
``workflow.transition``
The object is going through this transition.

* ``workflow.enter``
* ``workflow.[workflow name].enter``
* ``workflow.[workflow name].enter.[place name]``
The three events being dispatched are:

* ``workflow.announce``
* ``workflow.[workflow name].announce``
* ``workflow.[workflow name].announce.[transition name]``
* ``workflow.transition``
* ``workflow.[workflow name].transition``
* ``workflow.[workflow name].transition.[transition name]``

When a state transition is initiated, the events are fired in the following order:
``workflow.enter``
The object entered a new place. This is the first event where the object
is marked as being in the new place.

- guard: Validate whether the transition is allowed at all (:ref:`see below <workflow-usage-guard-events>`);
- leave: The object is about to leave a place;
- transition: The object is going through this transition;
- enter: The object entered a new place. This is the first event where the object' is marked as being in the new place;
- announce: Triggered once for each workflow that now is available for the object.
The three events being dispatched are:

* ``workflow.enter``
* ``workflow.[workflow name].enter``
* ``workflow.[workflow name].enter.[place name]``

``workflow.announce``
Triggered once for each workflow that now is available for the object.

The three events being dispatched are:

* ``workflow.announce``
* ``workflow.[workflow name].announce``
* ``workflow.[workflow name].announce.[transition name]``

Here is an example how to enable logging for every time a the "blog_publishing" workflow leaves a place::

use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Workflow\Event\Event;

class WorkflowLogger implements EventSubscriberInterface
{
public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

public function onLeave(Event $event)
{
$this->logger->alert(sprintf(
Expand All @@ -242,7 +261,7 @@ Here is an example how to enable logging for every time a the "blog_publishing"
implode(', ', $event->getTransition()->getTos())
));
}

public static function getSubscribedEvents()
{
return array(
Expand All @@ -253,14 +272,14 @@ Here is an example how to enable logging for every time a the "blog_publishing"

.. _workflow-usage-guard-events:

Guard events
Guard Events
~~~~~~~~~~~~

There are a special kind of events called "Guard events". Their event listeners
are invoked every time a call to ``Workflow::can``, ``Workflow::apply`` or
There are a special kind of events called "Guard events". Their event listeners
are invoked every time a call to ``Workflow::can``, ``Workflow::apply`` or
``Workflow::getEnabledTransitions`` is executed. With the guard events you may
add custom logic to decide what transitions that are valid or not. Here is a list
of the guard event names.
add custom logic to decide what transitions that are valid or not. Here is a list
of the guard event names.

* ``workflow.guard``
* ``workflow.[workflow name].guard``
Expand Down