|
8 | 8 |
|
9 | 9 | final class BuildConsumptionExtensionsPass implements CompilerPassInterface |
10 | 10 | { |
11 | | - /** |
12 | | - * @var string |
13 | | - */ |
14 | | - private $name; |
| 11 | + use FormatClientNameTrait; |
15 | 12 |
|
16 | | - public function __construct(string $clientName) |
17 | | - { |
18 | | - if (empty($clientName)) { |
19 | | - throw new \InvalidArgumentException('The name could not be empty.'); |
20 | | - } |
21 | | - |
22 | | - $this->name = $clientName; |
23 | | - } |
| 13 | + protected $name; |
24 | 14 |
|
25 | 15 | public function process(ContainerBuilder $container): void |
26 | 16 | { |
27 | | - $extensionsId = sprintf('enqueue.client.%s.consumption_extensions', $this->name); |
28 | | - if (false == $container->hasDefinition($extensionsId)) { |
29 | | - return; |
| 17 | + if (false == $container->hasParameter('enqueue.clients')) { |
| 18 | + throw new \LogicException('The "enqueue.clients" parameter must be set.'); |
30 | 19 | } |
31 | 20 |
|
32 | | - $tags = array_merge( |
33 | | - $container->findTaggedServiceIds('enqueue.consumption_extension'), |
34 | | - $container->findTaggedServiceIds('enqueue.consumption.extension') // TODO BC |
35 | | - ); |
| 21 | + $names = $container->getParameter('enqueue.clients'); |
36 | 22 |
|
37 | | - $groupByPriority = []; |
38 | | - foreach ($tags as $serviceId => $tagAttributes) { |
39 | | - foreach ($tagAttributes as $tagAttribute) { |
40 | | - $client = $tagAttribute['client'] ?? 'default'; |
| 23 | + foreach ($names as $name) { |
| 24 | + $this->name = $name; |
41 | 25 |
|
42 | | - if ($client !== $this->name && 'all' !== $client) { |
43 | | - continue; |
44 | | - } |
| 26 | + $extensionsId = $this->format('consumption_extensions'); |
| 27 | + if (false == $container->hasDefinition($extensionsId)) { |
| 28 | + throw new \LogicException(sprintf('Service "%s" not found', $extensionsId)); |
| 29 | + } |
| 30 | + |
| 31 | + $tags = array_merge( |
| 32 | + $container->findTaggedServiceIds('enqueue.consumption_extension'), |
| 33 | + $container->findTaggedServiceIds('enqueue.consumption.extension') // TODO BC |
| 34 | + ); |
| 35 | + |
| 36 | + $groupByPriority = []; |
| 37 | + foreach ($tags as $serviceId => $tagAttributes) { |
| 38 | + foreach ($tagAttributes as $tagAttribute) { |
| 39 | + $client = $tagAttribute['client'] ?? 'default'; |
45 | 40 |
|
46 | | - $priority = (int) ($tagAttribute['priority'] ?? 0); |
| 41 | + if ($client !== $this->name && 'all' !== $client) { |
| 42 | + continue; |
| 43 | + } |
47 | 44 |
|
48 | | - $groupByPriority[$priority][] = new Reference($serviceId); |
| 45 | + $priority = (int) ($tagAttribute['priority'] ?? 0); |
| 46 | + |
| 47 | + $groupByPriority[$priority][] = new Reference($serviceId); |
| 48 | + } |
49 | 49 | } |
50 | | - } |
51 | 50 |
|
52 | | - krsort($groupByPriority, SORT_NUMERIC); |
| 51 | + krsort($groupByPriority, SORT_NUMERIC); |
53 | 52 |
|
54 | | - $flatExtensions = []; |
55 | | - foreach ($groupByPriority as $extension) { |
56 | | - $flatExtensions = array_merge($flatExtensions, $extension); |
| 53 | + $flatExtensions = []; |
| 54 | + foreach ($groupByPriority as $extension) { |
| 55 | + $flatExtensions = array_merge($flatExtensions, $extension); |
| 56 | + } |
| 57 | + |
| 58 | + $extensionsService = $container->getDefinition($extensionsId); |
| 59 | + $extensionsService->replaceArgument(0, array_merge( |
| 60 | + $extensionsService->getArgument(0), |
| 61 | + $flatExtensions |
| 62 | + )); |
57 | 63 | } |
| 64 | + } |
58 | 65 |
|
59 | | - $extensionsService = $container->getDefinition($extensionsId); |
60 | | - $extensionsService->replaceArgument(0, array_merge( |
61 | | - $extensionsService->getArgument(0), |
62 | | - $flatExtensions |
63 | | - )); |
| 66 | + protected function getName(): string |
| 67 | + { |
| 68 | + return $this->name; |
64 | 69 | } |
65 | 70 | } |
0 commit comments