Completed
Push — master ( 103460...224772 )
by GBProd
02:10
created

ElasticaExtraExtension::load()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 9.3142
cc 2
eloc 12
nc 2
nop 2
crap 2
1
<?php
2
3
namespace GBProd\ElasticaExtraBundle\DependencyInjection;
4
5
use GBProd\ElasticaExtraBundle\Repository\IndexConfigurationRepository;
6
use Symfony\Component\Config\FileLocator;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
use Symfony\Component\DependencyInjection\Loader;
9
use Symfony\Component\DependencyInjection\Reference;
10
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
11
12
/**
13
 * Extension class for ElasticsearchExtra bundle
14
 *
15
 * @author gbprod <[email protected]>
16
 */
17
class ElasticaExtraExtension extends Extension
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 7
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 7
        $configuration = new Configuration();
25 7
        $config = $this->processConfiguration($configuration, $configs);
26
27 7
        $this->createIndexConfigurationRepository($config, $container);
28
29 7
        if (null !== $config['default_client']) {
30 1
            $container->setAlias(
31 1
                'gbprod.elastica_extra.default_client',
32 1
                $config['default_client']
33 1
            );
34 1
        }
35
36 7
        $loader = new Loader\YamlFileLoader(
37 7
            $container,
38 7
            new FileLocator(__DIR__ . '/../Resources/config')
39 7
        );
40
41 7
        $loader->load('services.yml');
42 7
    }
43
44 7
    private function createIndexConfigurationRepository(array $config, ContainerBuilder $container)
45
    {
46 1
        $container
47 7
            ->register(
48 7
                'gbprod.elastica_extra.index_configuration_repository',
49
                IndexConfigurationRepository::class
50 7
            )
51 7
            ->addArgument($config['indices'])
52
        ;
53 7
    }
54
}
55