Skip to content

Commit 74c5379

Browse files
authored
Add section about Workflows and State Machine validation
As suggested in symfony/symfony#33972 (comment)
1 parent 9a926b7 commit 74c5379

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

workflow/workflow-and-state-machine.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,4 +302,26 @@ to access the proper service::
302302
// ...
303303
}
304304

305+
Validation: automatic and manual
306+
--------------
307+
Workflows and state machines that are defined in a configuration file will be validated automatically during cache warmup. No validation is done upon object instantiation itself. This means that when a workflow or state machine is defined manually instead of using a configuration file, one should consider to perform validation manually as well using either (:class:`Symfony\\Component\\Workflow\\Validator\\WorkflowValidator`) or (:class:`Symfony\\Component\\Workflow\\Validator\\StateMachineValidator`), for example::
308+
309+
// ...
310+
use Symfony\Component\Workflow\Definition;
311+
use Symfony\Component\Workflow\StateMachine;
312+
use Symfony\Component\Workflow\Validator\StateMachineValidator;
313+
314+
$states = ['created', 'activated', 'deleted'];
315+
$stateTransitions = [
316+
new Transition('activate', 'created', 'activated'),
317+
new Transition('activate', 'created', 'deleted'), //This duplicate event "from" the "created" state is invalid
318+
new Transition('delete', 'activated', 'deleted'),
319+
];
320+
321+
$definition = new Definition($states, $stateTransitions); //No validation is done upon initialization
322+
323+
$validator = new StateMachineValidator();
324+
$validator->validate($definition, 'My First StateMachine'); //Throws InvalidDefinitionException in case of an invalid Definition
325+
326+
305327
.. _`Petri nets`: https://en.wikipedia.org/wiki/Petri_net

0 commit comments

Comments
 (0)