Completed
Pull Request — master (#917)
by Dmitry
08:52
created

ConfigSourcePass   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 28
ccs 0
cts 13
cp 0
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B process() 0 20 5
1
<?php
2
3
/**
4
 * This file is part of the FOSElasticaBundle project.
5
 *
6
 * (c) Tim Nagel <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\ElasticaBundle\DependencyInjection\Compiler;
13
14
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Reference;
17
18
class ConfigSourcePass implements CompilerPassInterface
19
{
20
    const SOURCE_TYPE_INDEX_TEMPLATE = 'index_template';
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    public function process(ContainerBuilder $container)
26
    {
27
        if (!$container->hasDefinition('fos_elastica.config_manager')) {
28
            return;
29
        }
30
31
        $indexSources = array();
32
        $indexTemplateSources = array();
33
        foreach (array_keys($container->findTaggedServiceIds('fos_elastica.config_source')) as $id) {
34
            $tag = $container->findDefinition($id)->getTag('fos_elastica.config_source');
35
            if (isset($tag[0]['source']) && $tag[0]['source'] === self::SOURCE_TYPE_INDEX_TEMPLATE) {
36
                $indexTemplateSources[] = new Reference($id);
37
            } else {
38
                $indexSources[] = new Reference($id);
39
            }
40
        }
41
42
        $container->getDefinition('fos_elastica.config_manager')->replaceArgument(0, $indexSources);
43
        $container->getDefinition('fos_elastica.config_manager')->replaceArgument(1, $indexTemplateSources);
44
    }
45
}
46