Completed
Push — master ( a36c27...010ee5 )
by GBProd
02:47
created

ElasticsearchExtraExtension   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 4
c 2
b 0
f 0
lcom 1
cbo 7
dl 0
loc 60
ccs 32
cts 32
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 15 1
A createIndexConfigurationRepository() 0 10 1
A createClientRepository() 0 12 1
A getClientsReferences() 0 14 1
1
<?php
2
3
namespace GBProd\ElasticsearchExtraBundle\DependencyInjection;
4
5
use Symfony\Component\Config\FileLocator;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\DependencyInjection\Loader;
8
use Symfony\Component\DependencyInjection\Reference;
9
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
10
11
/**
12
 * Extension class for ElasticsearchExtra bundle
13
 * 
14
 * @author gbprod <[email protected]>
15
 */
16
class ElasticsearchExtraExtension extends Extension
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    public function load(array $configs, ContainerBuilder $container)
22
    {
23 1
        $configuration = new Configuration();
24 1
        $config = $this->processConfiguration($configuration, $configs);
25
26 1
        $this->createIndexConfigurationRepository($config, $container);
27 1
        $this->createClientRepository($config, $container);
28
29 1
        $loader = new Loader\YamlFileLoader(
30 1
            $container, 
31 1
            new FileLocator(__DIR__.'/../Resources/config')
32 1
        );
33
        
34 1
        $loader->load('services.yml');
35 1
    }
36
    
37
    private function createIndexConfigurationRepository(array $config, ContainerBuilder $container) 
38
    {
39
        $container
40 1
            ->register(
41 1
                'gbprod.elasticsearch_extra.index_configuration_repository',
42
                'GBProd\ElasticsearchExtraBundle\Repository\IndexConfigurationRepository'
43 1
            )
44 1
            ->addArgument($config['clients'])
45
        ;
46 1
    }
47
    
48
    private function createClientRepository(array $config, ContainerBuilder $container) 
49
    {
50
        $container
51 1
            ->register(
52 1
                'gbprod.elasticsearch_extra.client_repository',
53
                'GBProd\ElasticsearchExtraBundle\Repository\ClientRepository'
54 1
            )
55 1
            ->addArgument(
56 1
                $this->getClientsReferences($config)
57 1
            )
58
        ;
59 1
    }
60
    
61
    private function getClientsReferences(array $config)
62
    {
63 1
        return array_map(
64 1
            function($clientId) {
65 1
                return new Reference(
66 1
                    sprintf(
67 1
                        'm6web_elasticsearch.client.%s',
68
                        $clientId
69 1
                    )
70 1
                );
71 1
            },
72 1
            array_keys($config['clients'])
73 1
        );
74
    }
75
}
76