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

AddTasksCompilerPass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 32
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 24 5
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 AddTasksCompilerPass 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 tasks
26
        $tag   = 'as3_post_process.task';
27
        $tasks = $container->findTaggedServiceIds($tag);
28
29
        foreach ($tasks as $id => $tagAttributes) {
30
            foreach ($tagAttributes as $attributes) {
31
                // Add the task to the manager service definition
32
                $priority = isset($attributes['priority']) ? $attributes['priority'] : 0;
33
                $definition->addMethodCall(
34
                    'addTask',
35
                    [new Reference($id), $priority]
36
                );
37
            }
38
        }
39
    }
40
}
41