Completed
Push — master ( 709dbb...f12a68 )
by Tobias
09:11
created

AddProvidersPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 8
nc 3
nop 1
1
<?php
2
3
/*
4
 * This file is part of the BazingaGeocoderBundle package.
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 *
8
 * @license    MIT License
9
 */
10
11
namespace Bazinga\GeocoderBundle\DependencyInjection\Compiler;
12
13
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
use Symfony\Component\DependencyInjection\Reference;
16
17
/**
18
 * @author William Durand <[email protected]>
19
 */
20
class AddProvidersPass implements CompilerPassInterface
21
{
22
    /**
23
     * @var \Symfony\Component\DependencyInjection\ContainerBuilder
24
     */
25
    protected $container;
26
27
    /**
28
     * Get all providers based on their tag (`bazinga_geocoder.provider`) and
29
     * register them.
30
     *
31
     * @param ContainerBuilder $container
32
     */
33
    public function process(ContainerBuilder $container)
34
    {
35
        if (!$container->hasDefinition('Geocoder\\ProviderAggregator')) {
36
            return;
37
        }
38
39
        $providers = [];
40
        foreach ($container->findTaggedServiceIds('bazinga_geocoder.provider') as $providerId => $attributes) {
41
            $providers[] = new Reference($providerId);
42
        }
43
44
        $geocoderDefinition = $container->getDefinition('Geocoder\\ProviderAggregator');
45
        $geocoderDefinition->addMethodCall('registerProviders', [$providers]);
46
    }
47
}
48