Completed
Pull Request — master (#233)
by De Cramer
10:00
created

ConfigPass::process()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.439
c 0
b 0
f 0
cc 5
eloc 16
nc 7
nop 1
1
<?php
2
3
namespace eXpansion\Framework\Config\DependencyInjection\Compiler;
4
5
use eXpansion\Framework\Config\Services\ConfigManagerInterface;
6
use eXpansion\Framework\Config\Services\ConfigUiManager;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\Compiler\PriorityTaggedServiceTrait;
9
use Symfony\Component\DependencyInjection\ContainerBuilder;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
/**
13
 * PluginPass to register all plugins to the plugin manager.
14
 *
15
 * @package eXpansion\Framework\Core\DependencyInjection\Compiler
16
 */
17
class ConfigPass implements CompilerPassInterface
18
{
19
    use PriorityTaggedServiceTrait;
20
21
    /**
22
     * Register all data providers to the Manager.
23
     *
24
     * @param ContainerBuilder $container
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->has(ConfigManagerInterface::class)) {
29
            return;
30
        }
31
        $definition = $container->getDefinition(ConfigManagerInterface::class);
32
33
        // Find all config's
34
        $configs = $container->findTaggedServiceIds('expansion.config');
35
        foreach ($configs as $id => $tags) {
36
            foreach ($tags as $attributes) {
37
                $definition->addMethodCall(
38
                    'registerConfig',
39
                    [new Reference($id), $id]
40
                );
41
            }
42
        }
43
44
        // Find all services to display configs.
45
        $definition = $container->getDefinition(ConfigUiManager::class);
46
        $services = $this->findAndSortTaggedServices('expansion.config.ui', $container);
47
        foreach($services as $service) {
48
            $definition->addMethodCall(
49
                'registerUi',
50
                [$service]
51
            );
52
        }
53
    }
54
}
55