Completed
Push — feature/EVO-7964_fundInfo-exte... ( 9219e4...25799b )
by Bastian
252:34 queued 245:35
created

ApiDefinitionLoaderPass::process()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 22
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.0039

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 15
cts 16
cp 0.9375
rs 8.9197
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
crap 4.0039
1
<?php
2
/**
3
 * ApiDefinitionLoaderPass
4
 */
5
6
namespace Graviton\ProxyBundle\DependencyInjection\Compiler;
7
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
10
use Symfony\Component\DependencyInjection\Reference;
11
12
/**
13
 * Class ApiDefinitionLoaderPass
14
 *
15
 * @package Graviton\ProxyExtensionBundle\Definition\Loader
16
 *
17
 * @author   List of contributors <https://github.com/libgraviton/graviton/graphs/contributors>
18
 * @license  http://opensource.org/licenses/gpl-license.php GNU Public License
19
 * @link     http://swisscom.ch
20
 */
21
class ApiDefinitionLoaderPass implements CompilerPassInterface
22
{
23
    /**
24
     * {@inheritDoc}
25
     *
26
     * @param ContainerBuilder $container Symfony Service container
27
     *
28
     * @return void
29
     */
30 2
    public function process(ContainerBuilder $container)
31
    {
32
        // always first check if the primary service is defined
33 2
        if (!$container->has('graviton.proxy.service.loaderfactory')) {
34
            return;
35
        }
36
37 2
        $definition = $container->findDefinition('graviton.proxy.service.loaderfactory');
38 2
        $taggedServices = $container->findTaggedServiceIds('graviton.proxy.definition.loader');
39
40 2
        foreach ($taggedServices as $id => $tags) {
41 2
            foreach ($tags as $attributes) {
42 2
                $definition->addMethodCall(
43 2
                    'addLoaderDefinition',
44
                    array(
45 2
                        new Reference($id),
46 2
                        $attributes["alias"]
47 1
                    )
48 1
                );
49 1
            }
50 1
        }
51 2
    }
52
}
53