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