Completed
Pull Request — develop (#512)
by Bastian
127:43 queued 62:46
created

ApiDefinitionLoaderPass::process()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 24
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.6845
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
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
     * @param ContainerBuilder $container Symfony Service container
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        // always first check if the primary service is defined
29
        if (!$container->has('graviton.proxy.service.loaderfactory')) {
30
            return;
31
        }
32
33
        $definition = $container->findDefinition('graviton.proxy.service.loaderfactory');
34
35
        // find all service IDs with the app.mail_transport tag
36
        $taggedServices = $container->findTaggedServiceIds('graviton.proxy.definition.loader');
37
38
        foreach ($taggedServices as $id => $tags) {
39
            foreach ($tags as $attributes) {
40
                $definition->addMethodCall(
41
                    'addLoaderDefinition',
42
                    array(
43
                        new Reference($id),
44
                        $attributes["alias"]
45
                    )
46
                );
47
            }
48
        }
49
    }
50
}
51