mirror of
https://github.com/symfony/symfony-docs.git
synced 2026-03-24 00:32:14 +01:00
Merge branch '5.4' into 6.4
* 5.4: Minor tweaks [Workflow] Do to talk about workflow, and explain what support option is for
This commit is contained in:
@@ -85,41 +85,6 @@ method to initialize the object property::
|
||||
// initiate workflow
|
||||
$workflow->getMarking($blogPost);
|
||||
|
||||
Using The Workflow Registry
|
||||
---------------------------
|
||||
|
||||
When you define multiple workflows you may consider using a ``Registry``,
|
||||
which is an object that stores and provides access to different workflows.
|
||||
A registry will also help you to decide if a workflow supports the object you
|
||||
are trying to use it with::
|
||||
|
||||
use Acme\Entity\BlogPost;
|
||||
use Acme\Entity\Newsletter;
|
||||
use Symfony\Component\Workflow\Registry;
|
||||
use Symfony\Component\Workflow\SupportStrategy\InstanceOfSupportStrategy;
|
||||
|
||||
$blogPostWorkflow = ...;
|
||||
$newsletterWorkflow = ...;
|
||||
|
||||
$registry = new Registry();
|
||||
$registry->addWorkflow($blogPostWorkflow, new InstanceOfSupportStrategy(BlogPost::class));
|
||||
$registry->addWorkflow($newsletterWorkflow, new InstanceOfSupportStrategy(Newsletter::class));
|
||||
|
||||
You can then use the registry to get the workflow for a specific object::
|
||||
|
||||
$blogPost = new BlogPost();
|
||||
$workflow = $registry->get($blogPost);
|
||||
|
||||
// initiate workflow
|
||||
$workflow->getMarking($blogPost);
|
||||
|
||||
.. caution::
|
||||
|
||||
Beware that injecting the ``Registry`` into your services is **not**
|
||||
recommended. Indeed, it prevents some optimization like lazy-loading
|
||||
from working and could be a performance hog. Instead, you should always
|
||||
inject the workflow you need.
|
||||
|
||||
Learn more
|
||||
----------
|
||||
|
||||
|
||||
@@ -81,6 +81,7 @@ Below is the configuration for the pull request state machine.
|
||||
marking_store:
|
||||
type: 'method'
|
||||
property: 'currentPlace'
|
||||
# The "supports" option is useful only if you are using Twig functions ('workflow_*')
|
||||
supports:
|
||||
- App\Entity\PullRequest
|
||||
initial_marking: start
|
||||
@@ -131,6 +132,7 @@ Below is the configuration for the pull request state machine.
|
||||
|
||||
<framework:marking-store type="method" property="currentPlace"/>
|
||||
|
||||
<!-- The "supports" option is useful only if you are using Twig functions ('workflow_*') -->
|
||||
<framework:support>App\Entity\PullRequest</framework:support>
|
||||
|
||||
<framework:place>start</framework:place>
|
||||
@@ -199,6 +201,7 @@ Below is the configuration for the pull request state machine.
|
||||
|
||||
$pullRequest
|
||||
->type('state_machine')
|
||||
// The "supports" option is useful only if you are using Twig functions ('workflow_*')
|
||||
->supports(['App\Entity\PullRequest'])
|
||||
->initialMarking(['start']);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user