Skip to content

Commit 9f70ec5

Browse files
committed
Merge branch '6.3' into 6.4
* 6.3: [Workflow] Revert deprecation about Registry
2 parents fb645e8 + f7cab93 commit 9f70ec5

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

components/workflow.rst

+35
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,41 @@ method to initialize the object property::
8585
// initiate workflow
8686
$workflow->getMarking($blogPost);
8787

88+
Using The Workflow Registry
89+
---------------------------
90+
91+
When you define multiple workflows you may consider using a ``Registry``,
92+
which is an object that stores and provides access to different workflows.
93+
A registry will also help you to decide if a workflow supports the object you
94+
are trying to use it with::
95+
96+
use Acme\Entity\BlogPost;
97+
use Acme\Entity\Newsletter;
98+
use Symfony\Component\Workflow\Registry;
99+
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
100+
101+
$blogPostWorkflow = ...;
102+
$newsletterWorkflow = ...;
103+
104+
$registry = new Registry();
105+
$registry->addWorkflow($blogPostWorkflow, new InstanceOfSupportStrategy(BlogPost::class));
106+
$registry->addWorkflow($newsletterWorkflow, new InstanceOfSupportStrategy(Newsletter::class));
107+
108+
You can then use the registry to get the workflow for a specific object::
109+
110+
$blogPost = new BlogPost();
111+
$workflow = $registry->get($blogPost);
112+
113+
// initiate workflow
114+
$workflow->getMarking($blogPost);
115+
116+
.. caution::
117+
118+
Beware that injecting the ``Registry`` into your services is **not**
119+
recommended. Indeed, it prevents some optimization like lazy-loading
120+
from working and could be a performance hog. Instead, you should always
121+
inject the workflow you need.
122+
88123
Learn more
89124
----------
90125

0 commit comments

Comments
 (0)