@@ -1123,7 +1123,8 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11231123 }
11241124 }
11251125 $ 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 );
11271128
11281129 // Create places
11291130 $ places = array_column ($ workflow ['places ' ], 'name ' );
@@ -1134,7 +1135,8 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11341135 $ definitionDefinition ->addArgument ($ places );
11351136 $ definitionDefinition ->addArgument ($ transitions );
11361137 $ 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 );
11381140
11391141 // Create MarkingStore
11401142 $ markingStoreDefinition = null ;
@@ -1148,14 +1150,26 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11481150 $ markingStoreDefinition = new Reference ($ workflow ['marking_store ' ]['service ' ]);
11491151 }
11501152
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+
11511160 // Create Workflow
11521161 $ workflowDefinition = new ChildDefinition (\sprintf ('%s.abstract ' , $ type ));
1153- $ workflowDefinition ->replaceArgument (0 , new Reference (\sprintf ( ' %s.definition ' , $ workflowId ) ));
1162+ $ workflowDefinition ->replaceArgument (0 , new Reference ($ definitionDefinitionId ));
11541163 $ workflowDefinition ->replaceArgument (1 , $ markingStoreDefinition );
11551164 $ workflowDefinition ->replaceArgument (3 , $ name );
11561165 $ workflowDefinition ->replaceArgument (4 , $ workflow ['events_to_dispatch ' ]);
11571166
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+ ]);
11591173 if ('workflow ' === $ type ) {
11601174 $ workflowDefinition ->addTag ('workflow.workflow ' , ['name ' => $ name ]);
11611175 } elseif ('state_machine ' === $ type ) {
@@ -1164,21 +1178,10 @@ private function registerWorkflowConfiguration(array $config, ContainerBuilder $
11641178
11651179 // Store to container
11661180 $ container ->setDefinition ($ workflowId , $ workflowDefinition );
1167- $ container ->setDefinition (\sprintf ( ' %s.definition ' , $ workflowId ) , $ definitionDefinition );
1181+ $ container ->setDefinition ($ definitionDefinitionId , $ definitionDefinition );
11681182 $ container ->registerAliasForArgument ($ workflowId , WorkflowInterface::class, $ name .'. ' .$ type );
11691183 $ container ->registerAliasForArgument ($ workflowId , WorkflowInterface::class, $ name );
11701184
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-
11821185 // Add workflow to Registry
11831186 if ($ workflow ['supports ' ]) {
11841187 foreach ($ workflow ['supports ' ] as $ supportedClassName ) {
0 commit comments