Completed
Push — master ( e4af37...216fab )
by Peter
03:05
created

VoterListenerPass::process()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 0
cts 14
cp 0
rs 8.7624
cc 5
eloc 10
nc 6
nop 1
crap 30
1
<?php
2
/**
3
 * GpsLab component.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2016, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
10
namespace GpsLab\Bundle\DomainEvent\DependencyInjection\Compiler;
11
12
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
13
use Symfony\Component\DependencyInjection\ContainerBuilder;
14
use Symfony\Component\DependencyInjection\Reference;
15
16
class VoterListenerPass implements CompilerPassInterface
17
{
18
    /**
19
     * @param ContainerBuilder $container
20
     */
21
    public function process(ContainerBuilder $container)
22
    {
23
        if (!$container->has('domain_event.locator.voter')) {
24
            return;
25
        }
26
27
        $current_locator = $container->findDefinition('domain_event.locator');
28
        $voter_locator = $container->findDefinition('domain_event.locator.voter');
29
30
        // register services only if current locator is voter locator
31
        if ($voter_locator === $current_locator) {
32
            foreach ($container->findTaggedServiceIds('domain_event.listener') as  $id => $attributes) {
33
                $voter_locator->addMethodCall('register', [new Reference($id)]);
34
            }
35
        }
36
37
        // BC: get services from old tag
38
        foreach ($container->findTaggedServiceIds('domain_event.voter_listener') as  $id => $attributes) {
39
            $voter_locator->addMethodCall('register', [new Reference($id)]);
40
        }
41
    }
42
}
43