11
11
use Symfony \Component \Workflow \MarkingStore \SingleStateMarkingStore ;
12
12
use Symfony \Component \Workflow \Registry ;
13
13
use Symfony \Component \Workflow \StateMachine ;
14
+ use Symfony \Component \Workflow \SupportStrategy \SupportStrategyInterface ;
14
15
use Symfony \Component \Workflow \Transition ;
15
16
use Symfony \Component \Workflow \Workflow ;
16
17
use Symfony \Component \Workflow \SupportStrategy \ClassInstanceSupportStrategy ;
21
22
class WorkflowRegistry
22
23
{
23
24
/**
24
- * @var Symfony\Component\Workflow\ Registry
25
+ * @var Registry
25
26
*/
26
27
private $ registry ;
27
28
@@ -35,13 +36,19 @@ class WorkflowRegistry
35
36
*/
36
37
private $ dispatcher ;
37
38
39
+ /**
40
+ * WorkflowRegistry constructor
41
+ *
42
+ * @param array $config
43
+ * @throws \ReflectionException
44
+ */
38
45
public function __construct (array $ config )
39
46
{
40
- $ this ->registry = new Registry ();
41
- $ this ->config = $ config ;
42
- $ this ->dispatcher = new EventDispatcher ();
47
+ $ this ->registry = new Registry ();
48
+ $ this ->config = $ config ;
49
+ $ this ->dispatcher = new EventDispatcher ();
43
50
44
- $ subscriber = new WorkflowSubscriber ();
51
+ $ subscriber = new WorkflowSubscriber ();
45
52
$ this ->dispatcher ->addSubscriber ($ subscriber );
46
53
47
54
foreach ($ this ->config as $ name => $ workflowData ) {
@@ -55,9 +62,9 @@ public function __construct(array $config)
55
62
$ builder ->addTransition (new Transition ($ transitionName , $ transition ['from ' ], $ transition ['to ' ]));
56
63
}
57
64
58
- $ definition = $ builder ->build ();
59
- $ markingStore = $ this ->getMakingStoreInstance ($ workflowData );
60
- $ workflow = $ this ->getWorkflowInstance ($ name , $ workflowData , $ definition , $ markingStore );
65
+ $ definition = $ builder ->build ();
66
+ $ markingStore = $ this ->getMarkingStoreInstance ($ workflowData );
67
+ $ workflow = $ this ->getWorkflowInstance ($ name , $ workflowData , $ definition , $ markingStore );
61
68
62
69
foreach ($ workflowData ['supports ' ] as $ supportedClass ) {
63
70
$ this ->add ($ workflow , $ supportedClass );
@@ -66,7 +73,8 @@ public function __construct(array $config)
66
73
}
67
74
68
75
/**
69
- * Return the $subject workflo
76
+ * Return the $subject workflow
77
+ *
70
78
* @param object $subject
71
79
* @param string $workflowName
72
80
* @return Workflow
@@ -78,31 +86,36 @@ public function get($subject, $workflowName = null)
78
86
79
87
/**
80
88
* Add a workflow to the subject
81
- * @param Workflow $workflow
82
- * @param Symfony\Component\Workflow\SupportStrategy\SupportStrategyInterface $supportStrategy
89
+ *
90
+ * @param Workflow $workflow
91
+ * @param SupportStrategyInterface $supportStrategy
83
92
*/
84
- public function add (Workflow $ workflow , $ supportStrategy )
93
+ public function add (Workflow $ workflow , SupportStrategyInterface $ supportStrategy )
85
94
{
86
- return $ this ->registry ->add ($ workflow , new ClassInstanceSupportStrategy ($ supportStrategy ));
95
+ $ this ->registry ->add ($ workflow , new ClassInstanceSupportStrategy ($ supportStrategy ));
87
96
}
88
97
89
98
/**
90
99
* Return the workflow instance
91
100
*
92
- * @param String $name
93
- * @param array $workflowData
94
- * @param Symfony\Component\Workflow\ Definition $definition
95
- * @param Symfony\Component\Workflow\MarkingStore\ MarkingStoreInterface $makingStore
96
- * @return Symfony\Component\Workflow\ Workflow
101
+ * @param String $name
102
+ * @param array $workflowData
103
+ * @param Definition $definition
104
+ * @param MarkingStoreInterface $markingStore
105
+ * @return Workflow
97
106
*/
98
- private function getWorkflowInstance ($ name , $ workflowData , Definition $ definition , MarkingStoreInterface $ markingStore )
99
- {
107
+ private function getWorkflowInstance (
108
+ $ name ,
109
+ array $ workflowData ,
110
+ Definition $ definition ,
111
+ MarkingStoreInterface $ markingStore
112
+ ) {
100
113
$ type = isset ($ workflowData ['type ' ]) ? $ workflowData ['type ' ] : 'workflow ' ;
101
114
$ className = Workflow::class;
102
115
103
116
if ($ type === 'state_machine ' ) {
104
117
$ className = StateMachine::class;
105
- } else if (isset ($ workflowData ['class ' ])) {
118
+ } elseif (isset ($ workflowData ['class ' ])) {
106
119
$ className = $ workflowData ['class ' ];
107
120
}
108
121
@@ -112,24 +125,21 @@ private function getWorkflowInstance($name, $workflowData, Definition $definitio
112
125
/**
113
126
* Return the making store instance
114
127
*
115
- * @param array $makingStoreData
116
- * @return Symfony\Component\Workflow\MarkingStore\MarkingStoreInterface
128
+ * @param array $workflowData
129
+ * @return MarkingStoreInterface
130
+ * @throws \ReflectionException
117
131
*/
118
- private function getMakingStoreInstance ( $ workflowData )
132
+ private function getMarkingStoreInstance ( array $ workflowData )
119
133
{
120
- $ makingStoreData = isset ($ workflowData ['marking_store ' ]) ? $ workflowData ['marking_store ' ] : [];
121
- $ type = isset ($ makingStoreData ['type ' ]) ? $ makingStoreData ['type ' ] : 'single_state ' ;
122
- $ className = SingleStateMarkingStore::class;
123
- $ arguments = [];
134
+ $ markingStoreData = isset ($ workflowData ['marking_store ' ]) ? $ workflowData ['marking_store ' ] : [];
135
+ $ type = isset ($ markingStoreData ['type ' ]) ? $ markingStoreData ['type ' ] : 'single_state ' ;
136
+ $ className = SingleStateMarkingStore::class;
137
+ $ arguments = isset ( $ markingStoreData [ ' arguments ' ]) ? $ markingStoreData [ ' arguments ' ] : [];
124
138
125
139
if ($ type === 'multiple_state ' ) {
126
140
$ className = MultipleStateMarkingStore::class;
127
- } else if (isset ($ workflowData ['class ' ])) {
128
- $ className = $ workflowData ['class ' ];
129
- }
130
-
131
- if (isset ($ makingStoreData ['arguments ' ])) {
132
- $ arguments = $ makingStoreData ['arguments ' ];
141
+ } elseif (isset ($ markingStoreData ['class ' ])) {
142
+ $ className = $ markingStoreData ['class ' ];
133
143
}
134
144
135
145
$ class = new \ReflectionClass ($ className );
0 commit comments