Skip to content

Commit 27247c7

Browse files
committed
Merge branch '4.4' into 5.0
* 4.4: Add section about Workflows and State Machine validation
2 parents 482e350 + 013132f commit 27247c7

File tree

1 file changed

+30
-1
lines changed

1 file changed

+30
-1
lines changed

workflow/workflow-and-state-machine.rst

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ Below is the configuration for the pull request state machine.
130130
</framework:marking-store>
131131
132132
<framework:support>App\Entity\PullRequest</framework:support>
133-
133+
134134
<framework:initial_marking>start</framework:initial_marking>
135135
136136
<framework:place>start</framework:place>
@@ -302,4 +302,33 @@ to access the proper service::
302302
// ...
303303
}
304304

305+
Automatic and Manual Validation
306+
-------------------------------
307+
308+
During cache warmup, Symfony validates the workflows and state machines that are
309+
defined in configuration files. If your workflows or state machines are defined
310+
programmatically instead of in a configuration file, you can validate them with
311+
the :class:`Symfony\\Component\\Workflow\\Validator\\WorkflowValidator` and
312+
:class:`Symfony\\Component\\Workflow\\Validator\\StateMachineValidator`::
313+
314+
// ...
315+
use Symfony\Component\Workflow\Definition;
316+
use Symfony\Component\Workflow\StateMachine;
317+
use Symfony\Component\Workflow\Validator\StateMachineValidator;
318+
319+
$states = ['created', 'activated', 'deleted'];
320+
$stateTransitions = [
321+
new Transition('activate', 'created', 'activated'),
322+
// This duplicate event "from" the "created" state is invalid
323+
new Transition('activate', 'created', 'deleted'),
324+
new Transition('delete', 'activated', 'deleted'),
325+
];
326+
327+
// No validation is done upon initialization
328+
$definition = new Definition($states, $stateTransitions);
329+
330+
$validator = new StateMachineValidator();
331+
// Throws InvalidDefinitionException in case of an invalid definition
332+
$validator->validate($definition, 'My First StateMachine');
333+
305334
.. _`Petri nets`: https://en.wikipedia.org/wiki/Petri_net

0 commit comments

Comments
 (0)