Completed
Pull Request — master (#47)
by Wachter
11:23
created

HandlerCompilerPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0067

Importance

Changes 0
Metric Value
dl 0
loc 16
ccs 10
cts 11
cp 0.9091
rs 9.7333
c 0
b 0
f 0
cc 3
nc 3
nop 1
crap 3.0067
1
<?php
2
3
/*
4
 * This file is part of php-task library.
5
 *
6
 * (c) php-task
7
 *
8
 * This source file is subject to the MIT license that is bundled
9
 * with this source code in the file LICENSE.
10
 */
11
12
namespace Task\TaskBundle\DependencyInjection;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
/**
19
 * Compiler pass which collects worker services.
20
 */
21
class HandlerCompilerPass implements CompilerPassInterface
22
{
23
    const REGISTRY_ID = 'task.handler.factory';
24
25
    const HANDLER_TAG = 'task.handler';
26
27
    /**
28
     * {@inheritdoc}
29
     */
30 2
    public function process(ContainerBuilder $container)
31
    {
32 2
        if (!$container->has(self::REGISTRY_ID)) {
33
            return;
34
        }
35
36 2
        $handler = [];
37 2
        $taggedServices = $container->findTaggedServiceIds(self::HANDLER_TAG);
38 2
        foreach ($taggedServices as $id => $tags) {
39 1
            $service = $container->getDefinition($id);
40 1
            $handler[$service->getClass()] = new Reference($id);
41
        }
42
43 2
        $definition = $container->findDefinition(self::REGISTRY_ID);
44 2
        $definition->replaceArgument(0, $handler);
45 2
    }
46
}
47