Skip to content

[Workflow] Revert deprecation about Registry #19065

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

Merged
merged 1 commit into from
Oct 24, 2023
Merged
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
35 changes: 35 additions & 0 deletions components/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,41 @@ 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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we talks about TaggedIterator('workflow') or TaggedLocator('workflow') somewhere?
If not we should talk about this before talking about the registry

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Learn more
----------

Expand Down