1515use Symfony \Component \DependencyInjection \ContainerBuilder ;
1616use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
1717use Symfony \Component \Workflow \Validator \DefinitionValidatorInterface ;
18- use Symfony \Component \Workflow \Validator \SinglePlaceWorkflowValidator ;
1918use Symfony \Component \Workflow \Validator \StateMachineValidator ;
2019use Symfony \Component \Workflow \Validator \WorkflowValidator ;
2120
2423 */
2524class ValidateWorkflowsPass implements CompilerPassInterface
2625{
27- /**
28- * @var DefinitionValidatorInterface[]
29- */
30- private $ validators = array ();
31-
3226 public function process (ContainerBuilder $ container )
3327 {
3428 $ taggedServices = $ container ->findTaggedServiceIds ('workflow.definition ' );
@@ -45,7 +39,7 @@ public function process(ContainerBuilder $container)
4539 throw new RuntimeException (sprintf ('The "marking_store" for the tag "workflow.definition" of service "%s" must be set. ' , $ id ));
4640 }
4741
48- $ this ->getValidator ($ tag )->validate ($ definition , $ tag ['name ' ]);
42+ $ this ->createValidator ($ tag )->validate ($ definition , $ tag ['name ' ]);
4943 }
5044 }
5145 }
@@ -55,23 +49,16 @@ public function process(ContainerBuilder $container)
5549 *
5650 * @return DefinitionValidatorInterface
5751 */
58- private function getValidator ($ tag )
52+ private function createValidator ($ tag )
5953 {
60- if ($ tag ['type ' ] === 'state_machine ' ) {
61- $ name = 'state_machine ' ;
62- $ class = StateMachineValidator::class;
63- } elseif ($ tag ['marking_store ' ] === 'scalar ' ) {
64- $ name = 'single_place ' ;
65- $ class = SinglePlaceWorkflowValidator::class;
66- } else {
67- $ name = 'workflow ' ;
68- $ class = WorkflowValidator::class;
54+ if ('state_machine ' === $ tag ['type ' ]) {
55+ return new StateMachineValidator ();
6956 }
7057
71- if (empty ( $ this -> validators [ $ name ]) ) {
72- $ this -> validators [ $ name ] = new $ class ( );
58+ if (' single_state ' === $ tag [ ' marking_store ' ] ) {
59+ return new WorkflowValidator ( true );
7360 }
7461
75- return $ this -> validators [ $ name ] ;
62+ return new WorkflowValidator () ;
7663 }
7764}
0 commit comments