8000 Used the new fluent interface for DefinitionBuilder example · symfony/symfony-docs@ee47e38 · GitHub
[go: up one dir, main page]

Skip to content

Commit ee47e38

Browse files
committed
Used the new fluent interface for DefinitionBuilder example
1 parent 2b1dbee commit ee47e38

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

components/workflow.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,23 @@ these statuses are called **places**. You can define the workflow like this::
4444
use Symfony\Component\Workflow\Workflow;
4545
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
4646

47-
$builder = new DefinitionBuilder();
48-
$builder->addPlaces(['draft', 'review', 'rejected', 'published']);
49-
50-
// Transitions are defined with a unique name, an origin place and a destination place
51-
$builder->addTransition(new Transition('to_review', 'draft', 'review'));
52-
$builder->addTransition(new Transition('publish', 'review', 'published'));
53-
$builder->addTransition(new Transition('reject', 'review', 'rejected'));
54-
55-
$definition = $builder->build();
47+
$definition = new DefinitionBuilder()
48+
->addPlaces(['draft', 'review', 'rejected', 'published'])
49+
// Transitions are defined with a unique name, an origin place and a destination place
50+
->addTransition(new Transition('to_review', 'draft', 'review'))
51+
->addTransition(new Transition('publish', 'review', 'published'))
52+
->addTransition(new Transition('reject', 'review', 'rejected'))
53+
->build()
54+
;
5655

5756
$marking = new SingleStateMarkingStore('currentState');
5857
$workflow = new Workflow($definition, $marking);
5958

59+
.. versionadded:: 3.3
60+
The fluent interface for the ``DefinitionBuilder`` class was introduced in
61+
Symfony 3.3. Before you had to call the ``addPlaces()``, ``addTransition()``
62+
and ``build()`` methods separately.
63+
6064
The ``Workflow`` can now help you to decide what actions are allowed
6165
on a blog post depending on what *place* it is in. This will keep your domain
6266
logic in one place and not spread all over your application.

0 commit comments

Comments
 (0)
0