15
15
use Symfony \Component \DependencyInjection \ContainerBuilder ;
16
16
use Symfony \Component \DependencyInjection \Exception \RuntimeException ;
17
17
use Symfony \Component \Workflow \Validator \DefinitionValidatorInterface ;
18
- use Symfony \Component \Workflow \Validator \SinglePlaceWorkflowValidator ;
19
18
use Symfony \Component \Workflow \Validator \StateMachineValidator ;
20
19
use Symfony \Component \Workflow \Validator \WorkflowValidator ;
21
20
24
23
*/
25
24
class ValidateWorkflowsPass implements CompilerPassInterface
26
25
{
27
- /**
28
- * @var DefinitionValidatorInterface[]
29
- */
30
- private $ validators = array ();
31
-
32
26
public function process (ContainerBuilder $ container )
33
27
{
34
28
$ taggedServices = $ container ->findTaggedServiceIds ('workflow.definition ' );
@@ -45,7 +39,7 @@ public function process(ContainerBuilder $container)
45
39
throw new RuntimeException (sprintf ('The "marking_store" for the tag "workflow.definition" of service "%s" must be set. ' , $ id ));
46
40
}
47
41
48
- $ this ->getValidator ($ tag )->validate ($ definition , $ tag ['name ' ]);
42
+ $ this ->createValidator ($ tag )->validate ($ definition , $ tag ['name ' ]);
49
43
}
50
44
}
51
45
}
@@ -55,23 +49,16 @@ public function process(ContainerBuilder $container)
55
49
*
56
50
* @return DefinitionValidatorInterface
57
51
*/
58
- private function getValidator ($ tag )
52
+ private function createValidator ($ tag )
59
53
{
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 ();
69
56
}
70
57
71
- if (empty ( $ this -> validators [ $ name ]) ) {
72
- $ this -> validators [ $ name ] = new $ class ( );
58
+ if (' single_state ' === $ tag [ ' marking_store ' ] ) {
59
+ return new WorkflowValidator ( true );
73
60
}
74
61
75
- return $ this -> validators [ $ name ] ;
62
+ return new WorkflowValidator () ;
76
63
}
77
64
}
0 commit comments