@@ -52,23 +52,7 @@ public function __construct(array $config)
52
52
$ this ->dispatcher ->addSubscriber ($ subscriber );
53
53
54
54
foreach ($ this ->config as $ name => $ workflowData ) {
55
- $ builder = new DefinitionBuilder ($ workflowData ['places ' ]);
56
-
57
- foreach ($ workflowData ['transitions ' ] as $ transitionName => $ transition ) {
58
- if (!is_string ($ transitionName )) {
59
- $ transitionName = $ transition ['name ' ];
60
- }
61
-
62
- $ builder ->addTransition (new Transition ($ transitionName , $ transition ['from ' ], $ transition ['to ' ]));
63
- }
64
-
65
- $ definition = $ builder ->build ();
66
- $ markingStore = $ this ->getMarkingStoreInstance ($ workflowData );
67
- $ workflow = $ this ->getWorkflowInstance ($ name , $ workflowData , $ definition , $ markingStore );
68
-
69
- foreach ($ workflowData ['supports ' ] as $ supportedClass ) {
70
- $ this ->add ($ workflow , $ supportedClass );
71
- }
55
+ $ this ->addFromArray ($ name , $ workflowData );
72
56
}
73
57
}
74
58
@@ -95,6 +79,34 @@ public function add(Workflow $workflow, SupportStrategyInterface $supportStrateg
95
79
$ this ->registry ->add ($ workflow , new ClassInstanceSupportStrategy ($ supportStrategy ));
96
80
}
97
81
82
+ /**
83
+ * Add a workflow to the registry from array
84
+ *
85
+ * @param string $name
86
+ * @param array $workflowData
87
+ * @throws \ReflectionException
88
+ */
89
+ public function addFromArray ($ name , array $ workflowData )
90
+ {
91
+ $ builder = new DefinitionBuilder ($ workflowData ['places ' ]);
92
+
93
+ foreach ($ workflowData ['transitions ' ] as $ transitionName => $ transition ) {
94
+ if (!is_string ($ transitionName )) {
95
+ $ transitionName = $ transition ['name ' ];
96
+ }
97
+
98
+ $ builder ->addTransition (new Transition ($ transitionName , $ transition ['from ' ], $ transition ['to ' ]));
99
+ }
100
+
101
+ $ definition = $ builder ->build ();
102
+ $ markingStore = $ this ->getMarkingStoreInstance ($ workflowData );
103
+ $ workflow = $ this ->getWorkflowInstance ($ name , $ workflowData , $ definition , $ markingStore );
104
+
105
+ foreach ($ workflowData ['supports ' ] as $ supportedClass ) {
106
+ $ this ->add ($ workflow , $ supportedClass );
107
+ }
108
+ }
109
+
98
110
/**
99
111
* Return the workflow instance
100
112
*
0 commit comments