Completed
Push — master ( 978d70...a938d7 )
by Joshua
33s
created

AddPluginsCompilerPass::process()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 12
nc 4
nop 1
1
<?php
2
3
namespace As3\Bundle\PostProcessBundle\DependencyInjection\Compiler;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
class AddPluginsCompilerPass implements CompilerPassInterface
10
{
11
    /**
12
     * Adds tagged autoloaders to the manager service
13
     *
14
     * @param   ContainerBuilder $container
15
     */
16
    public function process(ContainerBuilder $container)
17
    {
18
        $managerId = 'as3_post_process.task.manager';
19
        if (!$container->hasDefinition($managerId)) {
20
            return;
21
        }
22
        // Get the manager service definition
23
        $definition = $container->getDefinition($managerId);
24
25
        // Get the tagged plugins
26
        $tag     = 'as3_post_process.plugin';
27
        $plugins = $container->findTaggedServiceIds($tag);
28
29
        foreach ($plugins as $id => $tagAttributes) {
30
            foreach ($tagAttributes as $attributes) {
31
                // Add the plugin to the manager service definition
32
                $definition->addMethodCall(
33
                    'addPlugin',
34
                    [new Reference($id)]
35
                );
36
            }
37
        }
38
    }
39
}
40