1 | <?php |
||
27 | class PoolsPass implements CompilerPassInterface |
||
28 | { |
||
29 | |||
30 | /** |
||
31 | * Queue manager tag name. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | const QUEUE_MANAGER_TAG = 'gendoria_command_queue.send_manager'; |
||
36 | |||
37 | /** |
||
38 | * Prepares command queue pools based on bundle configuration. |
||
39 | * |
||
40 | * Function also attaches specific pools to services tagged with {@link QUEUE_MANAGER_TAG} tag. |
||
41 | * |
||
42 | * @param ContainerBuilder $container |
||
43 | * |
||
44 | * @throws InvalidArgumentException |
||
45 | */ |
||
46 | 12 | public function process(ContainerBuilder $container) |
|
47 | { |
||
48 | 12 | $this->setupPools($container); |
|
49 | |||
50 | 9 | $pools = $container->getParameter('gendoria_command_queue.pools'); |
|
51 | |||
52 | 9 | foreach ($container->findTaggedServiceIds(self::QUEUE_MANAGER_TAG) as $id => $tags) { |
|
53 | 9 | $def = $container->getDefinition($id); |
|
54 | 9 | $reflection = new ReflectionClass($def->getClass()); |
|
55 | 9 | if ($reflection->implementsInterface(QueueManagerInterface::class)) { |
|
56 | $this->setupSingleQueueManager($id, $def, $tags, $pools); |
||
57 | } elseif ($reflection->implementsInterface(MultipleQueueManagerInterface::class)) { |
||
58 | $this->setupMultipleQueueManager($id, $def, $tags, $pools); |
||
59 | } else { |
||
60 | throw new InvalidArgumentException(sprintf('Service "%s" does not implement one of required interfaces.', $id)); |
||
61 | } |
||
62 | } |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Setup pools. |
||
67 | * |
||
68 | * @param ContainerBuilder $container |
||
69 | * @throws InvalidArgumentException |
||
70 | * @return void |
||
71 | */ |
||
72 | 12 | private function setupPools(ContainerBuilder $container) |
|
98 | |||
99 | private function setupSingleQueueManager($id, Definition $def, array $tags, array $pools) |
||
121 | |||
122 | private function setupMultipleQueueManager($id, Definition $def, array $tags, array $pools) |
||
144 | } |
||
145 |