Completed
Pull Request — develop (#512)
by Bastian
128:48 queued 63:36
created

ApiDefinitionLoaderPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 24 4
1
<?php
2
/**
3
 * ApiDefinitionLoaderPass
4
 */
5
6
namespace Graviton\ProxyExtensionBundle\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
    public function process(ContainerBuilder $container)
31
    {
32
        // always first check if the primary service is defined
33
        if (!$container->has('graviton.proxy.service.loaderfactory')) {
34
            return;
35
        }
36
37
        $definition = $container->findDefinition('graviton.proxy.service.loaderfactory');
38
39
        // find all service IDs with the app.mail_transport tag
40
        $taggedServices = $container->findTaggedServiceIds('graviton.proxy.definition.loader');
41
42
        foreach ($taggedServices as $id => $tags) {
43
            foreach ($tags as $attributes) {
44
                $definition->addMethodCall(
45
                    'addLoaderDefinition',
46
                    array(
47
                        new Reference($id),
48
                        $attributes["alias"]
49
                    )
50
                );
51
            }
52
        }
53
    }
54
}
55