AddProvidersPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 13
rs 10
1
<?php
2
3
namespace DH\NavigationBundle\DependencyInjection\Compiler;
4
5
use DH\NavigationBundle\Provider\ProviderAggregator;
6
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Reference;
9
10
class AddProvidersPass implements CompilerPassInterface
11
{
12
    /**
13
     * Get all providers based on their tag (`dh_navigation.provider`) and register them.
14
     */
15
    public function process(ContainerBuilder $container): void
16
    {
17
        if (!$container->hasDefinition(ProviderAggregator::class)) {
18
            return;
19
        }
20
21
        $providers = [];
22
        foreach ($container->findTaggedServiceIds('dh_navigation.provider') as $providerId => $attributes) {
23
            $providers[] = new Reference($providerId);
24
        }
25
26
        $definition = $container->getDefinition(ProviderAggregator::class);
27
        $definition->addMethodCall('registerProviders', [$providers]);
28
    }
29
}
30