29
29
*/
30
30
class AddConsoleCommandPass implements CompilerPassInterface
31
31
{
32
- private const COMMAND_LOADER_SERVICE_ID = 'console.command_loader ' ;
33
- private const COMMAND_TAG = 'console.command ' ;
34
- private const NO_PRELOAD_TAG = 'container.no_preload ' ;
35
- private const PRIVATE_TAG_NAME = 'container.private ' ;
36
-
37
32
public function process (ContainerBuilder $ container )
38
33
{
39
- $ commandServices = $ container ->findTaggedServiceIds (self :: COMMAND_TAG , true );
34
+ $ commandServices = $ container ->findTaggedServiceIds (' console.command ' , true );
40
35
$ lazyCommandMap = [];
41
36
$ lazyCommandRefs = [];
42
37
$ serviceIds = [];
43
38
44
39
foreach ($ commandServices as $ id => $ tags ) {
45
40
$ definition = $ container ->getDefinition ($ id );
46
- $ definition ->addTag (self :: NO_PRELOAD_TAG );
41
+ $ definition ->addTag (' container.no_preload ' );
47
42
$ class = $ container ->getParameterBag ()->resolveValue ($ definition ->getClass ());
48
43
49
44
if (isset ($ tags [0 ]['command ' ])) {
@@ -53,7 +48,7 @@ public function process(ContainerBuilder $container)
53
48
throw new InvalidArgumentException (sprintf ('Class "%s" used for service "%s" cannot be found. ' , $ class , $ id ));
54
49
}
55
50
if (!$ r ->isSubclassOf (Command::class)) {
56
- throw new InvalidArgumentException (sprintf ('The service "%s" tagged "%s" must be a subclass of "%s". ' , $ id , self :: COMMAND_TAG , Command::class));
51
+ throw new InvalidArgumentException (sprintf ('The service "%s" tagged "%s" must be a subclass of "%s". ' , $ id , ' console.command ' , Command::class));
57
52
}
58
53
$ aliases = $ class ::getDefaultName ();
59
54
}
@@ -66,7 +61,7 @@ public function process(ContainerBuilder $container)
66
61
}
67
62
68
63
if (null === $ commandName ) {
69
- if (!$ definition ->isPublic () || $ definition ->isPrivate () || $ definition ->hasTag (self :: PRIVATE_TAG_NAME )) {
64
+ if (!$ definition ->isPublic () || $ definition ->isPrivate () || $ definition ->hasTag (' container.private ' )) {
70
65
$ commandId = 'console.command.public_alias. ' .$ id ;
71
66
$ container ->setAlias ($ commandId , $ id )->setPublic (true );
72
67
$ id = $ commandId ;
@@ -110,7 +105,7 @@ public function process(ContainerBuilder $container)
110
105
throw new InvalidArgumentException (sprintf ('Class "%s" used for service "%s" cannot be found. ' , $ class , $ id ));
111
106
}
112
107
if (!$ r ->isSubclassOf (Command::class)) {
113
- throw new InvalidArgumentException (sprintf ('The service "%s" tagged "%s" must be a subclass of "%s". ' , $ id , self :: COMMAND_TAG , Command::class));
108
+ throw new InvalidArgumentException (sprintf ('The service "%s" tagged "%s" must be a subclass of "%s". ' , $ id , ' console.command ' , Command::class));
114
109
}
115
110
$ description = $ class ::getDefaultDescription ();
116
111
}
@@ -126,9 +121,9 @@ public function process(ContainerBuilder $container)
126
121
}
127
122
128
123
$ container
129
- ->register (self :: COMMAND_LOADER_SERVICE_ID , ContainerCommandLoader::class)
124
+ ->register (' console.command_loader ' , ContainerCommandLoader::class)
130
125
->setPublic (true )
131
- ->addTag (self :: NO_PRELOAD_TAG )
126
+ ->addTag (' container.no_preload ' )
132
127
->setArguments ([ServiceLocatorTagPass::register ($ container , $ lazyCommandRefs ), $ lazyCommandMap ]);
133
128
134
129
$ container ->setParameter ('console.command.ids ' , $ serviceIds );
0 commit comments