1 | <?php |
||
8 | class GroupRunnersCompilerPass implements CompilerPassInterface |
||
9 | { |
||
10 | 43 | public function process(ContainerBuilder $container) |
|
11 | { |
||
12 | 43 | $noRunner = false === $container->hasDefinition('liip_monitor.runner'); |
|
13 | 43 | $noDefaultGroup = false === $container->hasParameter('liip_monitor.default_group'); |
|
14 | |||
15 | 43 | if ($noRunner || $noDefaultGroup) { |
|
16 | return; |
||
17 | } |
||
18 | |||
19 | 43 | $definition = $container->getDefinition('liip_monitor.runner'); |
|
20 | 43 | $container->removeDefinition('liip_monitor.runner'); |
|
21 | |||
22 | 43 | $defaultGroup = $container->getParameter('liip_monitor.default_group'); |
|
23 | |||
24 | 43 | $checkServices = $container->findTaggedServiceIds('liip_monitor.check'); |
|
25 | 43 | $checkCollectionServices = $container->findTaggedServiceIds('liip_monitor.check_collection'); |
|
26 | |||
27 | 43 | $groups = array_merge( |
|
28 | 43 | [$defaultGroup], |
|
29 | 43 | $this->getGroups($checkServices), |
|
30 | 43 | $this->getGroups($checkCollectionServices), |
|
31 | 43 | $this->getGroupsFromParameter($container) |
|
32 | ); |
||
33 | 43 | $groups = array_unique($groups); |
|
34 | |||
35 | 43 | $runners = []; |
|
36 | 43 | foreach ($groups as $group) { |
|
37 | 43 | $container->setDefinition('liip_monitor.runner_'.$group, clone $definition); |
|
38 | 43 | $runners[] = 'liip_monitor.runner_'.$group; |
|
39 | } |
||
40 | |||
41 | 43 | $container->setAlias('liip_monitor.runner', 'liip_monitor.runner_'.$defaultGroup); |
|
42 | 43 | $runner = $container->getAlias('liip_monitor.runner'); |
|
43 | 43 | $runner->setPublic(true); |
|
44 | |||
45 | 43 | $container->setParameter('liip_monitor.runners', $runners); |
|
46 | 43 | } |
|
47 | |||
48 | /** |
||
49 | * @return array |
||
50 | */ |
||
51 | 43 | private function getGroups(array $services) |
|
64 | |||
65 | /** |
||
66 | * @return array |
||
67 | */ |
||
68 | 43 | private function getGroupsFromParameter(ContainerBuilder $container) |
|
81 | } |
||
82 |