1 | <?php |
||
17 | class WorkerCompilerPass implements CompilerPassInterface |
||
18 | { |
||
19 | 3 | public function process(ContainerBuilder $container) |
|
20 | { |
||
21 | 3 | if (false === $container->hasDefinition('dtc_queue.worker_manager')) { |
|
22 | 3 | return; |
|
23 | } |
||
24 | |||
25 | 3 | $this->setupAliases($container); |
|
26 | |||
27 | 3 | $definition = $container->getDefinition('dtc_queue.worker_manager'); |
|
28 | 3 | $jobManagerRef = array(new Reference('dtc_queue.job_manager')); |
|
29 | |||
30 | 3 | $jobClass = $this->getJobClass($container); |
|
31 | 3 | $jobArchiveClass = $this->getJobClassArchive($container); |
|
32 | 3 | $container->setParameter('dtc_queue.class_job', $jobClass); |
|
33 | 3 | $container->setParameter('dtc_queue.class_job_archive', $jobArchiveClass); |
|
34 | 3 | $container->setParameter('dtc_queue.class_job_timing', $this->getClass($container, 'job_timing', |
|
35 | 3 | 'JobTiming', JobTiming::class)); |
|
36 | 3 | $container->setParameter('dtc_queue.class_run', $this->getClass($container, 'run', 'Run', Run::class)); |
|
37 | 3 | $container->setParameter('dtc_queue.class_run_archive', $this->getClass($container, 'run_archive', 'RunArchive', Run::class)); |
|
38 | |||
39 | 3 | $this->setupTaggedServices($container, $definition, $jobManagerRef, $jobClass); |
|
40 | 2 | $eventDispatcher = $container->getDefinition('dtc_queue.event_dispatcher'); |
|
41 | 2 | foreach ($container->findTaggedServiceIds('dtc_queue.event_subscriber') as $id => $attributes) { |
|
42 | $eventSubscriber = $container->getDefinition($id); |
||
43 | $eventDispatcher->addMethodCall('addSubscriber', [$eventSubscriber]); |
||
44 | } |
||
45 | 2 | $this->setupDoctrineManagers($container); |
|
46 | 2 | } |
|
47 | |||
48 | 3 | protected function setupAlias(ContainerBuilder $container, $defaultManagerType, $type) |
|
49 | { |
||
50 | 3 | $definitionName = 'dtc_queue.'.$type.'.'.$defaultManagerType; |
|
51 | 3 | if (!$container->hasDefinition($definitionName) && !$container->hasAlias($definitionName)) { |
|
52 | throw new InvalidConfigurationException("No job manager found for dtc_queue.'.$type.'.$defaultManagerType"); |
||
53 | } |
||
54 | 3 | if ($container->hasDefinition($definitionName)) { |
|
55 | 3 | $alias = new Alias('dtc_queue.'.$type.'.'.$defaultManagerType); |
|
56 | 3 | $container->setAlias('dtc_queue.'.$type, $alias); |
|
57 | } else { |
||
58 | $container->setAlias('dtc_queue.'.$type, $container->getAlias($definitionName)); |
||
59 | } |
||
60 | 3 | } |
|
61 | |||
62 | 3 | protected function setupAliases(ContainerBuilder $container) |
|
63 | { |
||
64 | 3 | $defaultManagerType = $container->getParameter('dtc_queue.default_manager'); |
|
65 | 3 | $this->setupAlias($container, $defaultManagerType, 'job_manager'); |
|
66 | 3 | $defaultRunManagerType = $container->getParameter('dtc_queue.run_manager'); |
|
67 | 3 | $this->setupAlias($container, $defaultRunManagerType, 'run_manager'); |
|
68 | 3 | } |
|
69 | |||
70 | /** |
||
71 | * @param ContainerBuilder $container |
||
72 | * @param Reference[] $jobManagerRef |
||
73 | * @param string $jobClass |
||
74 | */ |
||
75 | 3 | protected function setupTaggedServices(ContainerBuilder $container, Definition $definition, array $jobManagerRef, $jobClass) |
|
95 | |||
96 | 2 | protected function setupDoctrineManagers(ContainerBuilder $container) |
|
97 | { |
||
98 | 2 | $documentManager = $container->getParameter('dtc_queue.document_manager'); |
|
112 | |||
113 | /** |
||
114 | * @param $managerType |
||
115 | * |
||
116 | * @return null|string |
||
117 | */ |
||
118 | 3 | protected function getDirectory($managerType) |
|
134 | |||
135 | /** |
||
136 | * Determines the job class based on the queue manager type. |
||
137 | * |
||
138 | * @param ContainerBuilder $container |
||
139 | * |
||
140 | * @return mixed|string |
||
141 | * |
||
142 | * @throws InvalidConfigurationException |
||
143 | */ |
||
144 | 3 | protected function getJobClass(ContainerBuilder $container) |
|
159 | |||
160 | 3 | protected function getClass(ContainerBuilder $container, $type, $className, $baseClass) |
|
181 | |||
182 | /** |
||
183 | * @throws ClassNotFoundException |
||
184 | * @throws ClassNotSubclassException |
||
185 | */ |
||
186 | 3 | protected function testClass($className, $parent) |
|
197 | |||
198 | /** |
||
199 | * Determines the job class based on the queue manager type. |
||
200 | * |
||
201 | * @param ContainerBuilder $container |
||
202 | * |
||
203 | * @return mixed|string |
||
204 | * |
||
205 | * @throws ClassNotFoundException |
||
206 | * @throws ClassNotSubclassException |
||
207 | */ |
||
208 | 3 | protected function getJobClassArchive(ContainerBuilder $container) |
|
228 | } |
||
229 |