Skip to content

Commit 8f6a938

Browse files
committed
Merge branch '4.3' into 4.4
* 4.3: Fix example WhenUserRegisteredThenSendWelcomeEmail Remove double word Fix supervisor: need to use the group:* to start all processes in this group pushing autoconfigure into code block Update workflow.rst
2 parents f975e03 + 6a59686 commit 8f6a938

File tree

4 files changed

+27
-30
lines changed

4 files changed

+27
-30
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 in state "draft" by default
84-
$post = new BlogPost();
85-
$workflow = $registry->get($post);
85+
// Consider that $blogPost is in place "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 in state "review"
92+
$workflow->apply($blogPost, 'to_review'); // $blogPost is now in place "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
----------

messenger.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Messenger: Sync & Queued Message Handling
77
Messenger provides a message bus with the ability to send messages and then
88
handle them immediately in your application or send them through transports
99
(e.g. queues) to be handled later. To learn more deeply about it, read the
10-
:doc:`Messenger component docs </components/messenger>` docs.
10+
:doc:`Messenger component docs </components/messenger>`.
1111

1212
Installation
1313
------------
@@ -619,7 +619,7 @@ config and start your workers:
619619
620620
$ sudo supervisorctl update
621621
622-
$ sudo supervisorctl start messenger-consume
622+
$ sudo supervisorctl start messenger-consume:*
623623
624624
See the `Supervisor docs`_ for more details.
625625

messenger/message-recorder.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ using the ``DispatchAfterCurrentBusMiddleware`` and adding a
107107
108108
public function __invoke(UserRegistered $event)
109109
{
110-
$user = $this->em->getRepository(User::class)->find(new User($event->getUuid()));
110+
$user = $this->em->getRepository(User::class)->find($event->getUuid());
111111
112112
$this->mailer->send(new RawMessage('Welcome '.$user->getFirstName()));
113113
}

messenger/multiple_buses.rst

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,9 @@ you can restrict each handler to a specific bus using the ``messenger.message_ha
120120
services:
121121
App\MessageHandler\SomeCommandHandler:
122122
tags: [{ name: messenger.message_handler, bus: messenger.bus.commands }]
123+
# prevent handlers from being registered twice (or you can remove
124+
# the MessageHandlerInterface that autoconfigure uses to find handlers)
125+
autoconfigure: false
123126
124127
.. code-block:: xml
125128
@@ -147,14 +150,6 @@ you can restrict each handler to a specific bus using the ``messenger.message_ha
147150
This way, the ``App\MessageHandler\SomeCommandHandler`` handler will only be
148151
known by the ``messenger.bus.commands`` bus.
149152

150-
.. tip::
151-
152-
If you manually restrict handlers be sure to have ``autoconfigure`` disabled,
153-
or not implement the ``Symfony\Component\Messenger\Handler\MessageHandlerInterface``
154-
as this might cause your handler to be registered twice.
155-
156-
See :ref:`service autoconfiguration <services-autoconfigure>` for more information.
157-
158153
You can also automatically add this tag to a number of classes by following
159154
a naming convention and registering all of the handler services by name with
160155
the correct tag:

0 commit comments

Comments
 (0)