ElasticaExtraExtension::load()   A
last analyzed

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 0
Metric Value
dl 0
loc 21
ccs 16
cts 16
cp 1
rs 9.3142
c 0
b 0
f 0
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 10
    public function load(array $configs, ContainerBuilder $container)
23
    {
24 10
        $configuration = new Configuration();
25 10
        $config = $this->processConfiguration($configuration, $configs);
26
27 10
        $this->createIndexConfigurationRepository($config, $container);
28
29 10
        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 10
        $loader = new Loader\YamlFileLoader(
37 10
            $container,
38 10
            new FileLocator(__DIR__.'/../Resources/config')
39 10
        );
40
41 10
        $loader->load('services.yml');
42 10
    }
43
44 10
    private function createIndexConfigurationRepository(array $config, ContainerBuilder $container)
45
    {
46
        $container
47 10
            ->register(
48 10
                'gbprod.elastica_extra.index_configuration_repository',
49
                IndexConfigurationRepository::class
50 10
            )
51 10
            ->addArgument($config['indices'])
52
        ;
53 10
    }
54
}
55