ExpectationCompilerPass::process()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 4
nop 1
1
<?php
2
3
namespace Overwatch\ExpectationBundle\DependencyInjection;
4
5
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Reference;
8
9
/**
10
 * ExpectationCompilerPass
11
 * Finds all services tagged with EXPECTATION_TAG (i.e. all expection classes)
12
 * and notifies the EXPECTATION_MANAGER of their existance.
13
 */
14
class ExpectationCompilerPass implements CompilerPassInterface
15
{
16
    const EXPECTATION_MANAGER = 'overwatch_expectation.expectation_manager';
17
    const EXPECTATION_TAG = 'overwatch_expectation.expectation';
18
19
    public function process(ContainerBuilder $container)
20
    {
21
        if (!$container->hasDefinition(self::EXPECTATION_MANAGER)) {
22
            return;
23
        }
24
25
        $definition = $container->getDefinition(self::EXPECTATION_MANAGER);
26
27
        $taggedServices = $container->findTaggedServiceIds(self::EXPECTATION_TAG);
28
29
        foreach ($taggedServices as $id => $tags) {
30
            foreach ($tags as $attributes) {
31
                $definition->addMethodCall(
32
                    'add',
33
                    [new Reference($id), $attributes['alias']]
34
                );
35
            }
36
        }
37
    }
38
}
39