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

ProfilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 10
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 Bazinga\GeocoderBundle\DataCollector\GeocoderDataCollector;
14
use Bazinga\GeocoderBundle\DataCollector\ProfilingProvider;
15
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
16
use Symfony\Component\DependencyInjection\ContainerBuilder;
17
use Symfony\Component\DependencyInjection\Reference;
18
19
/**
20
 * Add Profiling on all providers with that 'bazinga_geocoder.provider'.
21
 *
22
 * @author Tobias Nyholm <[email protected]>
23
 */
24
class ProfilerPass implements CompilerPassInterface
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function process(ContainerBuilder $container)
30
    {
31
        if (!$container->hasDefinition(GeocoderDataCollector::class)) {
32
            return;
33
        }
34
35
        $dataCollector = $container->getDefinition(GeocoderDataCollector::class);
36
37
        foreach ($container->findTaggedServiceIds('bazinga_geocoder.provider') as $providerId => $attributes) {
38
            $container->register($providerId.'.debug', ProfilingProvider::class)
39
                ->setDecoratedService($providerId)
40
                ->setArguments([
41
                    new Reference($providerId.'.debug.inner'),
42
                ]);
43
            $dataCollector->addMethodCall('addInstance', [new Reference($providerId)]);
44
        }
45
    }
46
}
47