Completed
Pull Request — master (#2)
by Jacob
03:20
created

AddPluginsCompilerPass   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 23 4
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