Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita02a790

Browse files
committed
feature#11835 [Workflow] improve Workflow component documentation (noniagriconomie)
This PR was merged into the 4.3 branch.Discussion----------[Workflow] improve Workflow component documentationHiHere is a minor improvement of this part of the doc.- do not use deprecated marking store- use the right wording: place and transition instead of state and action- rewrite some vars nameThxCommits-------e0d6c11 Update workflow.rst
2 parents833234a +e0d6c11 commita02a790

File tree

1 file changed

+21
-19
lines changed

1 file changed

+21
-19
lines changed

‎components/workflow.rst‎

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,30 @@ a ``Definition`` and a way to write the states to the objects (i.e. an
3232
instance of a:class:`Symfony\\Component\\Workflow\\MarkingStore\\MarkingStoreInterface`).
3333

3434
Consider the following example for a blog post. A post can have one of a number
35-
of predefined statuses (`draft`, `review`, `rejected`, `published`). In a workflow,
35+
of predefined statuses (`draft`, `reviewed`, `rejected`, `published`). In a workflow,
3636
these statuses are called **places**. You can define the workflow like this::
3737

3838
use Symfony\Component\Workflow\DefinitionBuilder;
39-
use Symfony\Component\Workflow\MarkingStore\SingleStateMarkingStore;
39+
use Symfony\Component\Workflow\MarkingStore\MethodMarkingStore;
4040
use Symfony\Component\Workflow\Transition;
4141
use Symfony\Component\Workflow\Workflow;
4242

4343
$definitionBuilder = new DefinitionBuilder();
44-
$definition = $definitionBuilder->addPlaces(['draft', 'review', 'rejected', 'published'])
44+
$definition = $definitionBuilder->addPlaces(['draft', 'reviewed', 'rejected', 'published'])
4545
// Transitions are defined with a unique name, an origin place and a destination place
46-
->addTransition(new Transition('to_review', 'draft', 'review'))
47-
->addTransition(new Transition('publish', 'review', 'published'))
48-
->addTransition(new Transition('reject', 'review', 'rejected'))
46+
->addTransition(new Transition('to_review', 'draft', 'reviewed'))
47+
->addTransition(new Transition('publish', 'reviewed', 'published'))
48+
->addTransition(new Transition('reject', 'reviewed', 'rejected'))
4949
->build()
5050
;
5151

52-
$marking = new SingleStateMarkingStore('currentState');
52+
$singleState = true; // true if the subject can be in only one state at a given time
53+
$property = 'currentState' // subject property name where the state is stored
54+
$marking = new MethodMarkingStore($singleState, $property);
5355
$workflow = new Workflow($definition, $marking);
5456

55-
The ``Workflow`` can now help you to decide what actions are allowed
56-
on a blog post depending on what *place* it is in. This will keep your domain
57+
The ``Workflow`` can now help you to decide what*transitions* (actions) are allowed
58+
on a blog post depending on what *place*(state)it is in. This will keep your domain
5759
logic in one place and not spread all over your application.
5860

5961
When you define multiple workflows you should consider using a ``Registry``,
@@ -66,11 +68,11 @@ are trying to use it with::
6668
use Symfony\Component\Workflow\Registry;
6769
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
6870

69-
$blogWorkflow = ...
71+
$blogPostWorkflow = ...
7072
$newsletterWorkflow = ...
7173

7274
$registry = new Registry();
73-
$registry->addWorkflow($blogWorkflow, new InstanceOfSupportStrategy(BlogPost::class));
75+
$registry->addWorkflow($blogPostWorkflow, new InstanceOfSupportStrategy(BlogPost::class));
7476
$registry->addWorkflow($newsletterWorkflow, new InstanceOfSupportStrategy(Newsletter::class));
7577

7678
Usage
@@ -80,17 +82,17 @@ When you have configured a ``Registry`` with your workflows,
8082
you can retrieve a workflow from it and use it as follows::
8183

8284
// ...
83-
// Consider that $post is instate "draft" by default
84-
$post = new BlogPost();
85-
$workflow = $registry->get($post);
85+
// Consider that $blogPost is inplace "draft" by default
86+
$blogPost = new BlogPost();
87+
$workflow = $registry->get($blogPost);
8688

87-
$workflow->can($post, 'publish'); // False
88-
$workflow->can($post, 'to_review'); // True
89+
$workflow->can($blogPost, 'publish'); // False
90+
$workflow->can($blogPost, 'to_review'); // True
8991

90-
$workflow->apply($post, 'to_review'); // $post is now instate "review"
92+
$workflow->apply($blogPost, 'to_review'); // $blogPost is now inplace "reviewed"
9193

92-
$workflow->can($post, 'publish'); // True
93-
$workflow->getEnabledTransitions($post); //['publish', 'reject']
94+
$workflow->can($blogPost, 'publish'); // True
95+
$workflow->getEnabledTransitions($blogPost); //$blogPost can perform transition "publish" or "reject"
9496

9597
Learn more
9698
----------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp