-
-
Notifications
You must be signed in to change notification settings - Fork 5.2k
[Workflow] Do not talk about registry #17878
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,33 +58,12 @@ The ``Workflow`` can now help you to decide what *transitions* (actions) are all | |
on a blog post depending on what *place* (state) it is in. This will keep your domain | ||
logic in one place and not spread all over your application. | ||
|
||
When you define multiple workflows you should 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)); | ||
|
||
Usage | ||
----- | ||
|
||
When you have configured a ``Registry`` with your workflows, | ||
you can retrieve a workflow from it and use it as follows:: | ||
|
||
// ... | ||
// Consider that $blogPost is in place "draft" by default | ||
$blogPost = new BlogPost(); | ||
$workflow = $registry->get($blogPost); | ||
|
||
$workflow->can($blogPost, 'publish'); // False | ||
$workflow->can($blogPost, 'to_review'); // True | ||
|
@@ -103,7 +82,6 @@ method to initialize the object property:: | |
|
||
// ... | ||
$blogPost = new BlogPost(); | ||
$workflow = $registry->get($blogPost); | ||
|
||
// initiate workflow | ||
$workflow->getMarking($blogPost); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. $workflow is not defined anymore There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it is defined in line 55. |
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$workflow is not defined anymore
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is defined in line 55.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but shouldn't we show an example of injecting the workflow into a controller action or a service? There is no example for this, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I think it's mentioned here: