20
20
use Symfony \Component \Workflow \MarkingStore \MarkingStoreInterface ;
21
21
use Symfony \Component \Workflow \MarkingStore \MultipleStateMarkingStore ;
22
22
use Symfony \Component \Workflow \Metadata \MetadataStoreInterface ;
23
+ use Symfony \Component \Workflow \TransitionBlocker ;
23
24
24
25
/**
25
26
* @author Fabien Potencier <[email protected] >
@@ -92,11 +93,7 @@ public function can($subject, $transitionName)
92
93
continue ;
93
94
}
94
95
95
- try {
96
- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
97
- } catch (NotEnabledTransitionException $ e ) {
98
- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
99
- }
96
+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
100
97
101
98
if ($ transitionBlockerList ->isEmpty ()) {
102
99
return true ;
@@ -113,20 +110,26 @@ public function buildTransitionBlockerList($subject, string $transitionName): Tr
113
110
{
114
111
$ transitions = $ this ->definition ->getTransitions ();
115
112
$ marking = $ this ->getMarking ($ subject );
113
+
116
114
$ transitionBlockerList = null ;
117
115
118
116
foreach ($ transitions as $ transition ) {
119
117
if ($ transition ->getName () !== $ transitionName ) {
120
118
continue ;
121
119
}
122
120
123
- try {
124
- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
121
+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
122
+
123
+ if ($ transitionBlockerList ->isEmpty ()) {
124
+ return $ transitionBlockerList ;
125
+ }
125
126
127
+ // We prefer to return transitions blocker by something else than
128
+ // marking. Because it means the marking was OK Transition are
129
+ // deterministic : it's not possible to have many transition enabled
130
+ // at the same time that match the same marking with the same name
131
+ if (!$ transitionBlockerList ->has (TransitionBlocker::BLOCKED_BY_MARKING )) {
126
132
return $ transitionBlockerList ;
127
- } catch (NotEnabledTransitionException $ e ) {
128
- // a transition with the same name is defined for other places too
129
- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
130
133
}
131
134
}
132
135
@@ -153,15 +156,11 @@ public function apply($subject, $transitionName)
153
156
continue ;
154
157
}
155
158
156
- try {
157
- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
158
- } catch (NotEnabledTransitionException $ e ) {
159
- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
160
- }
161
-
162
- if ($ transitionBlockerList ->isEmpty ()) {
163
- $ approvedTransitionQueue [] = $ transition ;
159
+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
160
+ if (!$ transitionBlockerList ->isEmpty ()) {
161
+ continue ;
164
162
}
163
+ $ approvedTransitionQueue [] = $ transition ;
165
164
}
166
165
167
166
foreach ($ approvedTransitionQueue as $ transition ) {
@@ -202,12 +201,7 @@ public function getEnabledTransitions($subject)
202
201
$ marking = $ this ->getMarking ($ subject );
203
202
204
203
foreach ($ this ->definition ->getTransitions () as $ transition ) {
205
- try {
206
- $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
207
- } catch (NotEnabledTransitionException $ e ) {
208
- $ transitionBlockerList = $ e ->getTransitionBlockerList ();
209
- }
210
-
204
+ $ transitionBlockerList = $ this ->buildTransitionBlockerListForTransition ($ subject , $ marking , $ transition );
211
205
if ($ transitionBlockerList ->isEmpty ()) {
212
206
$ enabledTransitions [] = $ transition ;
213
207
}
@@ -252,7 +246,9 @@ private function buildTransitionBlockerListForTransition($subject, Marking $mark
252
246
{
253
247
foreach ($ transition ->getFroms () as $ place ) {
254
248
if (!$ marking ->has ($ place )) {
255
- throw new NotEnabledTransitionException ($ subject , $ transition ->getName (), $ this , new TransitionBlockerList (array (TransitionBlocker::createBlockedByMarking ($ marking ))));
249
+ return new TransitionBlockerList (array (
250
+ TransitionBlocker::createBlockedByMarking ($ marking ),
251
+ ));
256
252
}
257
253
}
258
254
0 commit comments