Skip to content

Used the new fluent interface for DefinitionBuilder example #7821

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

Closed
wants to merge 2 commits into from
Closed
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
22 changes: 13 additions & 9 deletions components/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,19 +44,23 @@ these statuses are called **places**. You can define the workflow like this::
use Symfony\Component\Workflow\Workflow;
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;

$builder = new DefinitionBuilder();
$builder->addPlaces(['draft', 'review', 'rejected', 'published']);

// Transitions are defined with a unique name, an origin place and a destination place
$builder->addTransition(new Transition('to_review', 'draft', 'review'));
$builder->addTransition(new Transition('publish', 'review', 'published'));
$builder->addTransition(new Transition('reject', 'review', 'rejected'));

$definition = $builder->build();
$definition = new DefinitionBuilder()
->addPlaces(['draft', 'review', 'rejected', 'published'])
// Transitions are defined with a unique name, an origin place and a destination place
->addTransition(new Transition('to_review', 'draft', 'review'))
->addTransition(new Transition('publish', 'review', 'published'))
->addTransition(new Transition('reject', 'review', 'rejected'))
->build()
;

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

.. versionadded:: 3.3
The fluent interface for the ``DefinitionBuilder`` class was introduced in
Symfony 3.3. Before you had to call the ``addPlaces()``, ``addTransition()``
and ``build()`` methods separately.

The ``Workflow`` can now help you to decide what actions are allowed
on a blog post depending on what *place* it is in. This will keep your domain
logic in one place and not spread all over your application.
Expand Down