Completed
Push — 1.1 ( 8cc80e...2e0749 )
by Simonas
02:35
created

ONGRElasticsearchExtension::load()   B

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 3
eloc 17
nc 2
nop 2
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[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 ONGR\ElasticsearchBundle\DependencyInjection;
13
14
use Symfony\Component\Config\FileLocator;
15
use Symfony\Component\DependencyInjection\ContainerBuilder;
16
use Symfony\Component\DependencyInjection\Loader;
17
use Symfony\Component\DependencyInjection\Definition;
18
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
19
use Symfony\Component\DependencyInjection\Reference;
20
21
/**
22
 * This is the class that loads and manages bundle configuration.
23
 */
24
class ONGRElasticsearchExtension extends Extension
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public function load(array $configs, ContainerBuilder $container)
30
    {
31
        $configuration = new Configuration();
32
        $config = $this->processConfiguration($configuration, $configs);
33
34
        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
35
        $loader->load('services.yml');
36
        $config['cache'] = isset($config['cache']) ?
37
            $config['cache'] : !$container->getParameter('kernel.debug');
38
39
        $container->setParameter('es.cache', $config['cache']);
40
        $container->setParameter('es.analysis', $config['analysis']);
41
        $container->setParameter('es.connections', $config['connections']);
42
        $container->setParameter('es.managers', $config['managers']);
43
        $definition = new Definition(
44
            'ONGR\ElasticsearchBundle\Service\ManagerFactory',
45
            [
46
                new Reference('es.metadata_collector'),
47
                new Reference('es.result_converter'),
48
                $container->getParameter('kernel.debug') ? new Reference('es.tracer') : null,
49
            ]
50
        );
51
        $container->setDefinition('es.manager_factory', $definition);
52
    }
53
}
54