@@ -1123,7 +1123,8 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
1123
1123
}
1124
1124
}
1125
1125
$ metadataStoreDefinition ->replaceArgument (2 , $ transitionsMetadataDefinition );
1126
- $ container ->setDefinition (\sprintf ('%s.metadata_store ' , $ workflowId ), $ metadataStoreDefinition );
1126
+ $ metadataStoreId = \sprintf ('%s.metadata_store ' , $ workflowId );
1127
+ $ container ->setDefinition ($ metadataStoreId , $ metadataStoreDefinition );
1127
1128
1128
1129
// Create places
1129
1130
$ places = array_column ($ workflow ['places ' ], 'name ' );
@@ -1134,7 +1135,8 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
1134
1135
$ definitionDefinition ->addArgument ($ places );
1135
1136
$ definitionDefinition ->addArgument ($ transitions );
1136
1137
$ definitionDefinition ->addArgument ($ initialMarking );
1137
- $ definitionDefinition ->addArgument (new Reference (\sprintf ('%s.metadata_store ' , $ workflowId )));
1138
+ $ definitionDefinition ->addArgument (new Reference ($ metadataStoreId ));
1139
+ $ definitionDefinitionId = \sprintf ('%s.definition ' , $ workflowId );
1138
1140
1139
1141
// Create MarkingStore
1140
1142
$ markingStoreDefinition = null ;
@@ -1148,14 +1150,26 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
1148
1150
$ markingStoreDefinition = new Reference ($ workflow ['marking_store ' ]['service ' ]);
1149
1151
}
1150
1152
1153
+ // Validation
1154
+ $ workflow ['definition_validators ' ][] = match ($ workflow ['type ' ]) {
1155
+ 'state_machine ' => Workflow \Validator \StateMachineValidator::class,
1156
+ 'workflow ' => Workflow \Validator \WorkflowValidator::class,
1157
+ default => throw new \LogicException (\sprintf ('Invalid workflow type "%s". ' , $ workflow ['type ' ])),
1158
+ };
1159
+
1151
1160
// Create Workflow
1152
1161
$ workflowDefinition = new ChildDefinition (\sprintf ('%s.abstract ' , $ type ));
1153
- $ workflowDefinition ->replaceArgument (0 , new Reference (\sprintf ( ' %s.definition ' , $ workflowId ) ));
1162
+ $ workflowDefinition ->replaceArgument (0 , new Reference ($ definitionDefinitionId ));
1154
1163
$ workflowDefinition ->replaceArgument (1 , $ markingStoreDefinition );
1155
1164
$ workflowDefinition ->replaceArgument (3 , $ name );
1156
1165
$ workflowDefinition ->replaceArgument (4 , $ workflow ['events_to_dispatch ' ]);
1157
1166
1158
- $ workflowDefinition ->addTag ('workflow ' , ['name ' => $ name , 'metadata ' => $ workflow ['metadata ' ]]);
1167
+ $ workflowDefinition ->addTag ('workflow ' , [
1168
+ 'name ' => $ name ,
1169
+ 'metadata ' => $ workflow ['metadata ' ],
1170
+ 'definition_validators ' => $ workflow ['definition_validators ' ],
1171
+ 'definition_id ' => $ definitionDefinitionId ,
1172
+ ]);
1159
1173
if ('workflow ' === $ type ) {
1160
1174
$ workflowDefinition ->addTag ('workflow.workflow ' , ['name ' => $ name ]);
1161
1175
} elseif ('state_machine ' === $ type ) {
@@ -1164,21 +1178,10 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
1164
1178
1165
1179
// Store to container
1166
1180
$ container ->setDefinition ($ workflowId , $ workflowDefinition );
1167
- $ container ->setDefinition (\sprintf ( ' %s.definition ' , $ workflowId ) , $ definitionDefinition );
1181
+ $ container ->setDefinition ($ definitionDefinitionId , $ definitionDefinition );
1168
1182
$ container ->registerAliasForArgument ($ workflowId , WorkflowInterface::class, $ name .'. ' .$ type );
1169
1183
$ container ->registerAliasForArgument ($ workflowId , WorkflowInterface::class, $ name );
1170
1184
1171
- // Validate Workflow
1172
- if ('state_machine ' === $ workflow ['type ' ]) {
1173
- $ validator = new Workflow \Validator \StateMachineValidator ();
1174
- } else {
1175
- $ validator = new Workflow \Validator \WorkflowValidator ();
1176
- }
1177
-
1178
- $ trs = array_map (fn (Reference $ ref ): Workflow \Transition => $ container ->get ((string ) $ ref ), $ transitions );
1179
- $ realDefinition = new Workflow \Definition ($ places , $ trs , $ initialMarking );
1180
- $ validator ->validate ($ realDefinition , $ name );
1181
-
1182
1185
// Add workflow to Registry
1183
1186
if ($ workflow ['supports ' ]) {
1184
1187
foreach ($ workflow ['supports ' ] as $ supportedClassName ) {
0 commit comments