Test Failed
Pull Request — master (#7)
by Jim
03:47
created

DriverCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 21
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
dl 0
loc 21
rs 9.3142
c 1
b 1
f 0
cc 3
eloc 11
nc 3
nop 1
1
<?php
2
3
4
namespace Jarobe\TaskRunnerBundle\DependencyInjection\Compiler;
5
6
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
class DriverCompilerPass implements CompilerPassInterface
12
{
13
14
    /**
15
     * You can modify the container here before it is dumped to PHP code.
16
     *
17
     * @param ContainerBuilder $container
18
     */
19
    public function process(ContainerBuilder $container)
20
    {
21
        $tagName = 'jarobe.task_runner.driver';
22
        $factoryServiceName = 'jarobe.task_runner.driver_factory';
23
24
        if (!$container->has($factoryServiceName)) {
25
            return;
26
        }
27
28
        $definition = $container->findDefinition($factoryServiceName);
29
        $taggedServices = $container->findTaggedServiceIds($tagName);
30
31
        $drivers = [];
32
        foreach ($taggedServices as $id => $tags) {
33
            // add the transport service to the ChainTransport service
34
            $drivers[] = new Reference($id);
35
        }
36
37
        $definition->replaceArgument(0, $drivers);
38
39
    }
40
}