Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita8c5161

Browse files
committed
Fixed workflows
1 parent51a537a commita8c5161

File tree

4 files changed

+251
-263
lines changed

4 files changed

+251
-263
lines changed

‎messenger/multiple_buses.rst‎

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -70,31 +70,23 @@ an **event bus**. The event bus could have zero or more subscribers.
7070
..code-block::php
7171
7272
// config/packages/messenger.php
73-
$container->loadFromExtension('framework', [
74-
'messenger' => [
75-
// The bus that is going to be injected when injecting MessageBusInterface
76-
'default_bus' => 'command.bus',
77-
'buses' => [
78-
'command.bus' => [
79-
'middleware' => [
80-
'validation',
81-
'doctrine_transaction',
82-
],
83-
],
84-
'query.bus' => [
85-
'middleware' => [
86-
'validation',
87-
],
88-
],
89-
'event.bus' => [
90-
'default_middleware' => 'allow_no_handlers',
91-
'middleware' => [
92-
'validation',
93-
],
94-
],
95-
],
96-
],
97-
]);
73+
use Symfony\Config\FrameworkConfig;
74+
75+
return static function (FrameworkConfig $framework) {
76+
// The bus that is going to be injected when injecting MessageBusInterface
77+
$framework->messenger()->defaultBus('command.bus');
78+
79+
$commandBus = $framework->messenger()->bus('command.bus');
80+
$commandBus->middleware()->id('validation');
81+
$commandBus->middleware()->id('doctrine_transaction');
82+
83+
$queryBus = $framework->messenger()->bus('query.bus');
84+
$queryBus->middleware()->id('validation');
85+
86+
$eventBus = $framework->messenger()->bus('event.bus');
87+
$eventBus->defaultMiddleware('allow_no_handlers');
88+
$eventBus->middleware()->id('validation');
89+
};
9890
9991
This will create three new services:
10092

‎workflow.rst‎

Lines changed: 115 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -120,43 +120,40 @@ like this:
120120
121121
// config/packages/workflow.php
122122
use App\Entity\BlogPost;
123-
124-
$container->loadFromExtension('framework', [
125-
'workflows' => [
126-
'blog_publishing' => [
127-
'type' => 'workflow', // or 'state_machine'
128-
'audit_trail' => [
129-
'enabled' => true
130-
],
131-
'marking_store' => [
132-
'type' => 'method',
133-
'property' => 'currentPlace',
134-
],
135-
'supports' => [BlogPost::class],
136-
'initial_marking' => 'draft',
137-
'places' => [
138-
'draft',
139-
'reviewed',
140-
'rejected',
141-
'published',
142-
],
143-
'transitions' => [
144-
'to_review' => [
145-
'from' => 'draft',
146-
'to' => 'reviewed',
147-
],
148-
'publish' => [
149-
'from' => 'reviewed',
150-
'to' => 'published',
151-
],
152-
'reject' => [
153-
'from' => 'reviewed',
154-
'to' => 'rejected',
155-
],
156-
],
157-
],
158-
],
159-
]);
123+
use Symfony\Config\FrameworkConfig;
124+
125+
return static function (FrameworkConfig $framework) {
126+
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
127+
$blogPublishing
128+
->type('workflow') // or 'state_machine'
129+
->supports([BlogPost::class])
130+
->initialMarking(['draft']);
131+
132+
$blogPublishing->auditTrail()->enabled(true);
133+
$blogPublishing->markingStore()
134+
->type('method')
135+
->property('currentPlace');
136+
137+
$blogPublishing->place()->name('draft');
138+
$blogPublishing->place()->name('reviewed');
139+
$blogPublishing->place()->name('rejected');
140+
$blogPublishing->place()->name('published');
141+
142+
$blogPublishing->transition()
143+
->name('to_review')
144+
->from(['draft'])
145+
->to(['reviewed']);
146+
147+
$blogPublishing->transition()
148+
->name('publish')
149+
->from(['reviewed'])
150+
->to(['published']);
151+
152+
$blogPublishing->transition()
153+
->name('reject')
154+
->from(['reviewed'])
155+
->to(['rejected']);
156+
};
160157
161158
..tip::
162159

@@ -553,23 +550,25 @@ to :ref:`Guard events <workflow-usage-guard-events>`, which are always fired:
553550
..code-block::php
554551
555552
// config/packages/workflow.php
556-
$container->loadFromExtension('framework', [
553+
use Symfony\Config\FrameworkConfig;
554+
555+
return static function (FrameworkConfig $framework) {
557556
// ...
558-
'workflows' => [
559-
'blog_publishing' => [
560-
// you can pass one or more event names
561-
'events_to_dispatch' => [
562-
'workflow.leave',
563-
'workflow.completed',
564-
],
565-
566-
// pass an empty array to not dispatch any event
567-
'events_to_dispatch' => [],
568-
569-
// ...
570-
],
571-
],
572-
]);
557+
558+
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
559+
560+
// ...
561+
// you can pass one or more event names
562+
$blogPublishing->eventsToDispatch([
563+
'workflow.leave',
564+
'workflow.completed',
565+
]);
566+
567+
// pass an empty array to not dispatch any event
568+
$blogPublishing->eventsToDispatch([]);
569+
570+
// ...
571+
};
573572
574573
You can also disable a specific event from being fired when applying a transition::
575574

@@ -731,36 +730,33 @@ transition. The value of this option is any valid expression created with the
731730
..code-block::php
732731
733732
// config/packages/workflow.php
734-
use App\Entity\BlogPost;
735-
736-
$container->loadFromExtension('framework', [
737-
'workflows' => [
738-
'blog_publishing' => [
739-
// ... previous configuration
740-
741-
'transitions' => [
742-
'to_review' => [
743-
// the transition is allowed only if the current user has the ROLE_REVIEWER role.
744-
'guard' => 'is_granted("ROLE_REVIEWER")',
745-
'from' => 'draft',
746-
'to' => 'reviewed',
747-
],
748-
'publish' => [
749-
// or "is_anonymous", "is_remember_me", "is_fully_authenticated", "is_granted"
750-
'guard' => 'is_authenticated',
751-
'from' => 'reviewed',
752-
'to' => 'published',
753-
],
754-
'reject' => [
755-
// or any valid expression language with "subject" referring to the post
756-
'guard' => 'is_granted("ROLE_ADMIN") and subject.isStatusReviewed()',
757-
'from' => 'reviewed',
758-
'to' => 'rejected',
759-
],
760-
],
761-
],
762-
],
763-
]);
733+
use Symfony\Config\FrameworkConfig;
734+
735+
return static function (FrameworkConfig $framework) {
736+
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
737+
// ... previous configuration
738+
739+
$blogPublishing->transition()
740+
->name('to_review')
741+
// the transition is allowed only if the current user has the ROLE_REVIEWER role.
742+
->guard('is_granted("ROLE_REVIEWER")')
743+
->from(['draft'])
744+
->to(['reviewed']);
745+
746+
$blogPublishing->transition()
747+
->name('publish')
748+
// or "is_anonymous", "is_remember_me", "is_fully_authenticated", "is_granted"
749+
->guard('is_authenticated')
750+
->from(['reviewed'])
751+
->to(['published']);
752+
753+
$blogPublishing->transition()
754+
->name('reject')
755+
// or any valid expression language with "subject" referring to the post
756+
->guard('is_granted("ROLE_ADMIN") and subject.isStatusReviewed()')
757+
->from(['reviewed'])
758+
->to(['rejected']);
759+
};
764760
765761
You can also use transition blockers to block and return a user-friendly error
766762
message when you stop a transition from happening.
@@ -945,42 +941,43 @@ be only the title of the workflow or very complex objects:
945941
..code-block::php
946942
947943
// config/packages/workflow.php
948-
$container->loadFromExtension('framework', [
944+
use Symfony\Config\FrameworkConfig;
945+
946+
return static function (FrameworkConfig $framework) {
947+
$blogPublishing = $framework->workflows()->workflows('blog_publishing');
948+
// ... previous configuration
949+
950+
$blogPublishing->metadata([
951+
'title' => 'Blog Publishing Workflow'
952+
]);
953+
949954
// ...
950-
'workflows' => [
951-
'blog_publishing' => [
952-
'metadata' => [
953-
'title' => 'Blog Publishing Workflow',
954-
],
955-
// ...
956-
'places' => [
957-
'draft' => [
958-
'metadata' => [
959-
'max_num_of_words' => 500,
960-
],
961-
],
962-
// ...
963-
],
964-
'transitions' => [
965-
'to_review' => [
966-
'from' => 'draft',
967-
'to' => 'review',
968-
'metadata' => [
969-
'priority' => 0.5,
970-
],
971-
],
972-
'publish' => [
973-
'from' => 'reviewed',
974-
'to' => 'published',
975-
'metadata' => [
976-
'hour_limit' => 20,
977-
'explanation' => 'You can not publish after 8 PM.',
978-
],
979-
],
980-
],
981-
],
982-
],
983-
]);
955+
956+
$blogPublishing->place()
957+
->name('draft')
958+
->metadata([
959+
'max_num_of_words' => 500,
960+
]);
961+
962+
// ...
963+
964+
$blogPublishing->transition()
965+
->name('to_review')
966+
->from(['draft'])
967+
->to(['reviewed'])
968+
->metadata([
969+
'priority' => 0.5,
970+
]);
971+
972+
$blogPublishing->transition()
973+
->name('publish')
974+
->from(['reviewed'])
975+
->to(['published'])
976+
->metadata([
977+
'hour_limit' => 20,
978+
'explanation' => 'You can not publish after 8 PM.',
979+
]);
980+
};
984981
985982
Then you can access this metadata in your controller as follows::
986983

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp