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