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

AddTasksCompilerPass::process()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 24
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 5
eloc 13
nc 5
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 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