Completed
Pull Request — master (#154)
by De Cramer
02:58
created

VoteFactoriesPass::process()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 9
nc 3
nop 1
1
<?php
2
3
4
namespace eXpansion\Bundle\VoteManager\DependencyInjection\Compiler;
5
6
use eXpansion\Bundle\VoteManager\Services\VoteService;
7
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
8
use Symfony\Component\DependencyInjection\ContainerBuilder;
9
use Symfony\Component\DependencyInjection\Reference;
10
11
12
/**
13
 * Class VoteFactoriesPass
14
 *
15
 * @package eXpansion\Bundle\VoteManager\DependencyInjection\Compiler;
16
 * @author  oliver de Cramer <[email protected]>
17
 */
18
class VoteFactoriesPass implements CompilerPassInterface
19
{
20
21
    /**
22
     * You can modify the container here before it is dumped to PHP code.
23
     *
24
     * @param ContainerBuilder $container
25
     */
26
    public function process(ContainerBuilder $container)
27
    {
28
        if (!$container->has(VoteService::class)) {
29
            return;
30
        }
31
        $definition = $container->getDefinition(VoteService::class);
32
33
        $voteFactorieReferences = [];
34
        $voteFactories = $container->findTaggedServiceIds('expansion.vote_manager.vote');
35
        foreach ($voteFactories as $voteFactoryId => $data) {
36
            $voteFactorieReferences[] = new Reference($voteFactoryId);
37
        }
38
39
        $definition->replaceArgument('$voteFactories', $voteFactorieReferences);
40
    }
41
}