16
16
use Symfony \Component \Workflow \Event \GuardEvent ;
17
17
use Symfony \Component \Workflow \Exception \LogicException ;
18
18
use Symfony \Component \Workflow \MarkingStore \MarkingStoreInterface ;
19
+ use Symfony \Component \Workflow \MarkingStore \PropertyAccessorMarkingStore ;
19
20
20
21
/**
21
22
* @author Fabien Potencier <fabien@symfony.com>
@@ -29,10 +30,10 @@ class Workflow
29
30
private $ dispatcher ;
30
31
private $ name ;
31
32
32
- public function __construct (Definition $ definition , MarkingStoreInterface $ markingStore , EventDispatcherInterface $ dispatcher = null , $ name = 'unnamed ' )
33
+ public function __construct (Definition $ definition , MarkingStoreInterface $ markingStore = null , EventDispatcherInterface $ dispatcher = null , $ name = 'unnamed ' )
33
34
{
34
35
$ this ->definition = $ definition ;
35
- $ this ->markingStore = $ markingStore ;
36
+ $ this ->markingStore = $ markingStore ?: new PropertyAccessorMarkingStore () ;
36
37
$ this ->dispatcher = $ dispatcher ;
37
38
$ this ->name = $ name ;
38
39
}
@@ -163,7 +164,7 @@ public function getName()
163
164
* @param Marking $marking
164
165
* @param Transition $transition
165
166
*
166
- * @return bool|void boolean true if this transition is guarded, ie you cannot use it.
167
+ * @return bool|void boolean true if this transition is guarded, ie you cannot use it
167
168
*/
168
169
private function guardTransition ($ subject , Marking $ marking , Transition $ transition )
169
170
{
@@ -253,25 +254,21 @@ private function getTransitions($transitionName)
253
254
{
254
255
$ transitions = $ this ->definition ->getTransitions ();
255
256
256
- $ namedTransitions = array_filter (
257
- $ transitions ,
258
- function (Transition $ transition ) use ($ transitionName ) {
259
- return $ transitionName === $ transition ->getName ();
260
- }
261
- );
257
+ $ transitions = array_filter ($ transitions , function (Transition $ transition ) use ($ transitionName ) {
258
+ return $ transitionName === $ transition ->getName ();
259
+ });
262
260
263
- if (empty ($ namedTransitions )) {
264
- throw new LogicException (
265
- sprintf ('Transition "%s" does not exist for workflow "%s". ' , $ transitionName , $ this ->name )
266
- );
261
+ if (!$ transitions ) {
262
+ throw new LogicException (sprintf ('Transition "%s" does not exist for workflow "%s". ' , $ transitionName , $ this ->name ));
267
263
}
268
264
269
- return $ namedTransitions ;
265
+ return $ transitions ;
270
266
}
271
267
272
268
/**
273
- * Return the first Transition in $transitions that is valid for the $subject and $marking. null is returned when
274
- * you cannot do any Transition in $transitions on the $subject.
269
+ * Return the first Transition in $transitions that is valid for the
270
+ * $subject and $marking. null is returned when you cannot do any Transition
271
+ * in $transitions on the $subject.
275
272
*
276
273
* @param object $subject
277
274
* @param Marking $marking
@@ -292,7 +289,5 @@ private function getTransitionForSubject($subject, Marking $marking, array $tran
292
289
return $ transition ;
293
290
}
294
291
}
295
-
296
- return ;
297
292
}
298
293
}
0 commit comments