5
5
use Enqueue \Client \CommandSubscriberInterface ;
6
6
use Enqueue \Client \Route ;
7
7
use Enqueue \Client \RouteCollection ;
8
+ use Enqueue \Symfony \DiUtils ;
8
9
use Symfony \Component \DependencyInjection \Compiler \CompilerPassInterface ;
9
10
use Symfony \Component \DependencyInjection \ContainerBuilder ;
10
11
11
12
final class BuildCommandSubscriberRoutesPass implements CompilerPassInterface
12
13
{
13
- use FormatClientNameTrait;
14
-
15
- protected $ name ;
16
-
17
14
public function process (ContainerBuilder $ container ): void
18
15
{
19
16
if (false == $ container ->hasParameter ('enqueue.clients ' )) {
20
17
throw new \LogicException ('The "enqueue.clients" parameter must be set. ' );
21
18
}
22
19
23
20
$ names = $ container ->getParameter ('enqueue.clients ' );
21
+ $ defaultName = $ container ->getParameter ('enqueue.default_client ' );
24
22
25
23
foreach ($ names as $ name ) {
26
- $ this -> name = $ name ;
27
- $ routeCollectionId = sprintf ( ' enqueue.client.%s. route_collection ', $ this -> name );
24
+ $ diUtils = DiUtils:: create (ClientFactory:: MODULE , $ name) ;
25
+ $ routeCollectionId = $ diUtils -> format ( ' route_collection ' );
28
26
if (false == $ container ->hasDefinition ($ routeCollectionId )) {
29
27
throw new \LogicException (sprintf ('Service "%s" not found ' , $ routeCollectionId ));
30
28
}
@@ -47,9 +45,9 @@ public function process(ContainerBuilder $container): void
47
45
}
48
46
49
47
foreach ($ tagAttributes as $ tagAttribute ) {
50
- $ client = $ tagAttribute ['client ' ] ?? ' default ' ;
48
+ $ client = $ tagAttribute ['client ' ] ?? $ defaultName ;
51
49
52
- if ($ client !== $ this -> name && 'all ' !== $ client ) {
50
+ if ($ client !== $ name && 'all ' !== $ client ) {
53
51
continue ;
54
52
}
55
53
@@ -103,9 +101,4 @@ public function process(ContainerBuilder $container): void
103
101
));
104
102
}
105
103
}
106
-
107
- protected function getName (): string
108
- {
109
- return $ this ->name ;
110
- }
111
104
}
0 commit comments