DriverCompilerPass::process()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

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